473,498 Members | 37 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL server instead of trigger

zachster17
30 New Member
Hello all,

I have 2 tables (tblAddProviderProfessional and tblAddProvider). There are other tables such as tblAddProviderFacility and so forth. tblAddProvider is a table that has similar data for all types of requests to add provider into the database. The other tables (i.e. tblAddProviderProfessional) has data that is unique to Professionals being added into the database. I'm trying my first attempt at Instead of triggers and can't quite get it to work.

Below is the code I'm using right now:

Expand|Select|Wrap|Line Numbers
  1. -- ================================================
  2. -- Template generated from Template Explorer using:
  3. -- Create Trigger (New Menu).SQL
  4. --
  5. -- Use the Specify Values for Template Parameters 
  6. -- command (Ctrl-Shift-M) to fill in the parameter 
  7. -- values below.
  8. --
  9. -- See additional Create Trigger templates for more
  10. -- examples of different Trigger statements.
  11. --
  12. -- This block of comments will not be included in
  13. -- the definition of the function.
  14. -- ================================================
  15. SET ANSI_NULLS ON
  16. GO
  17. SET QUOTED_IDENTIFIER ON
  18. GO
  19.  
  20. CREATE TRIGGER pmf_trgProviderAddProf_add> 
  21.    ON  pmf_vwProviderAddProf_add
  22.    INSTEAD OF INSERT
  23. AS 
  24. BEGIN
  25.  
  26. Declare @AddID    int
  27.  
  28.     SET NOCOUNT ON;
  29.  
  30.     -- Add record first to main Provider Add Table
  31.     INSERT INTO pmf_tblAddProvider
  32.         (EffectiveDate, RequestRep, SubmitDate, AttachedDoc, PublishInDir,
  33.         TaxID1,TaxID2,PrimaryLocContact1, ContactType1, ContactType2, ContactType3,
  34.         ContactType4, ContactAddrOne1, ContactAddrOne2, ContactAddrOne3, ContactAddrOne4,
  35.         ContactAddrTwo1, ContactAddrTwo2, ContactAddrTwo3, ContactAddrTwo4, ContactCity1,
  36.         ContactCity2, ContactCity3, ContactCity4, ContactState1, ContactState2, ContactState3,
  37.         ContactState4, ContactZip1, ContactZip2, ContactZip3, ContactZip4, ContactPhone1,
  38.         ContactPhone2, ContactPhone3, ContactPhone4, ContactPhoneExt1, ContactPhoneExt2,
  39.         ContactPhoneExt3, ContactPhoneExt4, ContactFax1, ContactFax2, ContactFax3, ContactFax4,
  40.         Contact2SameAs01, Contact4SameAs01, NetworkEncore, NetworkEncircle, NetworkOther,
  41.         NetworkOtherValue, NetworkRejectUSA, NetworkRejectMPlan, GroupXRef1, GroupXRef2,
  42.         GroupXRef3, NpiValue1, NpiValue2, NpiType1, NpiType2, Comments)
  43.     SELECT
  44.         (EffectiveDate, RequestRep, SubmitDate, AttachedDoc, PublishInDir,
  45.         TaxID1,TaxID2,PrimaryLocContact1, ContactType1, ContactType2, ContactType3,
  46.         ContactType4, ContactAddrOne1, ContactAddrOne2, ContactAddrOne3, ContactAddrOne4,
  47.         ContactAddrTwo1, ContactAddrTwo2, ContactAddrTwo3, ContactAddrTwo4, ContactCity1,
  48.         ContactCity2, ContactCity3, ContactCity4, ContactState1, ContactState2, ContactState3,
  49.         ContactState4, ContactZip1, ContactZip2, ContactZip3, ContactZip4, ContactPhone1,
  50.         ContactPhone2, ContactPhone3, ContactPhone4, ContactPhoneExt1, ContactPhoneExt2,
  51.         ContactPhoneExt3, ContactPhoneExt4, ContactFax1, ContactFax2, ContactFax3, ContactFax4,
  52.         Contact2SameAs01, Contact4SameAs01, NetworkEncore, NetworkEncircle, NetworkOther,
  53.         NetworkOtherValue, NetworkRejectUSA, NetworkRejectMPlan, GroupXRef1, GroupXRef2,
  54.         GroupXRef3, NpiValue1, NpiValue2, NpiType1, NpiType2, Comments FROM Inserted)
  55.  
  56.     -- Get identity value (from the Add Provider record)
  57.     SET @AddID = @@IDENTITY
  58.  
  59.     -- Add record next to the Professional Table
  60.     INSERT INTO pmf_tblAddProviderProf
  61.         (AddID, LastName, FirstName, MiddleInitial, MedicalTitle, DateOfBirth, SSN, Gender,
  62.         Specialty1, Specialty2, FacilityBased, CredApproval, FeeSchedID1, FeeSchedID2, FeeSchedID3,
  63.         DefaultDisc1, DefaultDisc2, DefaultDisc3, AnesMulti1, AnesMulti2, AnesMulti3)
  64.     SELECT
  65.         (@AddID, LastName, FirstName, MiddleInitial, MedicalTitle, DateOfBirth, SSN, Gender,
  66.         Specialty1, Specialty2, FacilityBased, CredApproval, FeeSchedID1, FeeSchedID2, FeeSchedID3,
  67.         DefaultDisc1, DefaultDisc2, DefaultDisc3, AnesMulti1, AnesMulti2, AnesMulti3 FROM Inserted)        
  68.  
  69. END
  70. GO
  71.  
And the errors I get are:

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '>'.
Msg 102, Level 15, State 1, Line 26
Incorrect syntax near ','.
Msg 102, Level 15, State 1, Line 47
Incorrect syntax near ','.

Again, I'm very new to SQL Server so my issues are probably relatively easy to solve; let me knwo if you'd like any more info!

Thanks,

Zach
Feb 8 '08 #1
4 2101
zachster17
30 New Member
Another note is that this trigger is being used to insert a record into a view that combines the fields for both tables.
Feb 8 '08 #2
ck9663
2,878 Recognized Expert Specialist
check your script, there's a "greater than" at the end of your create line...

"CREATE TRIGGER pmf_trgProviderAddProf_add>"

try deleting it....

-- ck
Feb 8 '08 #3
zachster17
30 New Member
Ck,

Thanks; that was a rookie mistake. I did that but I'm still getting the other errors; any ideas?
Feb 8 '08 #4
ck9663
2,878 Recognized Expert Specialist
i think your error is on your INSERT....

i think it's

INSERT INTO TABLE (COL1, COL2) SELECT COL1, COL2 FROM MYTABLE

or

INSERT INTO TABLE (COL1, COL2) (SELECT COL1, COL2 FROM MYTABLE)

NOT

INSERT INTO TABLE (COL1, COL2) SELECT (COL1, COL2 FROM MYTABLE)

either remove your parenthesis after the SELECT part or place it before the SELECT keyword, not after....

-- ck
Feb 8 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3505
by: kevin jin | last post by:
Hi, I did read Andrew's article about SQL Server trigger. After a 'Insert' trigger is fired,is there any way we can modify newly added data in virtual 'Insert' table before put them to the...
4
22182
by: DTB | last post by:
I am having trouble creating an INSTEAD OF trigger in SQL Server to replicate a BEFORE UPDATE trigger from ORACLE. Here is a sample of the ORACLE BEFORE UPDATE trigger: CREATE TRIGGER myTRIGGER ON...
7
16769
by: Aidan Whitehall | last post by:
Have gone through BOL and Google, but can't find the answer... please help with a simple Q. I'm trying to create a simple cascade delete trigger in SQL Server 7 where deleting "parent" records in...
7
12081
by: iqbal | last post by:
Hi all, We have an application through which we are bulk inserting rows into a view. The definition of the view is such that it selects columns from a table on a remote server. I have added the...
5
4504
by: William of Ockham | last post by:
Hi, I was asked to recreate a new clean database for our developers because the current one they use is not entirely up to date. So I created a new database and I run into the followin strange...
17
3552
by: Trevor Best | last post by:
I don't know if this has been reported before but it appears to be a bug with Access. If I create two tables both with an identity column then create an insert trigger on table1 that inserts a...
2
1939
by: dbuchanan52 | last post by:
Hello, I am building an application for Windows Forms using. I am new to SQL Server 'Views'. Are the following correct understanding of their use? 1.) I believe a view can be referenced in a...
2
20722
by: dba_222 | last post by:
Dear Experts, I'm an Oracle guy, who is being given more SQL Server assignments lately. I've been looking for things on the web about this, but I can't anything so far. In Oracle, I you...
8
1972
by: Tony Toews [MVP] | last post by:
Thanks to a posting by fellow MVP Steve Foster On a computer that is running Windows Vista, Windows Server 2008, or Windows XP, an incorrect value is returned when an application queries the...
0
7124
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6998
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5460
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4904
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.