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: -
-- ================================================
-
-- Template generated from Template Explorer using:
-
-- Create Trigger (New Menu).SQL
-
--
-
-- Use the Specify Values for Template Parameters
-
-- command (Ctrl-Shift-M) to fill in the parameter
-
-- values below.
-
--
-
-- See additional Create Trigger templates for more
-
-- examples of different Trigger statements.
-
--
-
-- This block of comments will not be included in
-
-- the definition of the function.
-
-- ================================================
-
SET ANSI_NULLS ON
-
GO
-
SET QUOTED_IDENTIFIER ON
-
GO
-
-
CREATE TRIGGER pmf_trgProviderAddProf_add>
-
ON pmf_vwProviderAddProf_add
-
INSTEAD OF INSERT
-
AS
-
BEGIN
-
-
Declare @AddID int
-
-
SET NOCOUNT ON;
-
-
-- Add record first to main Provider Add Table
-
INSERT INTO pmf_tblAddProvider
-
(EffectiveDate, RequestRep, SubmitDate, AttachedDoc, PublishInDir,
-
TaxID1,TaxID2,PrimaryLocContact1, ContactType1, ContactType2, ContactType3,
-
ContactType4, ContactAddrOne1, ContactAddrOne2, ContactAddrOne3, ContactAddrOne4,
-
ContactAddrTwo1, ContactAddrTwo2, ContactAddrTwo3, ContactAddrTwo4, ContactCity1,
-
ContactCity2, ContactCity3, ContactCity4, ContactState1, ContactState2, ContactState3,
-
ContactState4, ContactZip1, ContactZip2, ContactZip3, ContactZip4, ContactPhone1,
-
ContactPhone2, ContactPhone3, ContactPhone4, ContactPhoneExt1, ContactPhoneExt2,
-
ContactPhoneExt3, ContactPhoneExt4, ContactFax1, ContactFax2, ContactFax3, ContactFax4,
-
Contact2SameAs01, Contact4SameAs01, NetworkEncore, NetworkEncircle, NetworkOther,
-
NetworkOtherValue, NetworkRejectUSA, NetworkRejectMPlan, GroupXRef1, GroupXRef2,
-
GroupXRef3, NpiValue1, NpiValue2, NpiType1, NpiType2, Comments)
-
SELECT
-
(EffectiveDate, RequestRep, SubmitDate, AttachedDoc, PublishInDir,
-
TaxID1,TaxID2,PrimaryLocContact1, ContactType1, ContactType2, ContactType3,
-
ContactType4, ContactAddrOne1, ContactAddrOne2, ContactAddrOne3, ContactAddrOne4,
-
ContactAddrTwo1, ContactAddrTwo2, ContactAddrTwo3, ContactAddrTwo4, ContactCity1,
-
ContactCity2, ContactCity3, ContactCity4, ContactState1, ContactState2, ContactState3,
-
ContactState4, ContactZip1, ContactZip2, ContactZip3, ContactZip4, ContactPhone1,
-
ContactPhone2, ContactPhone3, ContactPhone4, ContactPhoneExt1, ContactPhoneExt2,
-
ContactPhoneExt3, ContactPhoneExt4, ContactFax1, ContactFax2, ContactFax3, ContactFax4,
-
Contact2SameAs01, Contact4SameAs01, NetworkEncore, NetworkEncircle, NetworkOther,
-
NetworkOtherValue, NetworkRejectUSA, NetworkRejectMPlan, GroupXRef1, GroupXRef2,
-
GroupXRef3, NpiValue1, NpiValue2, NpiType1, NpiType2, Comments FROM Inserted)
-
-
-- Get identity value (from the Add Provider record)
-
SET @AddID = @@IDENTITY
-
-
-- Add record next to the Professional Table
-
INSERT INTO pmf_tblAddProviderProf
-
(AddID, LastName, FirstName, MiddleInitial, MedicalTitle, DateOfBirth, SSN, Gender,
-
Specialty1, Specialty2, FacilityBased, CredApproval, FeeSchedID1, FeeSchedID2, FeeSchedID3,
-
DefaultDisc1, DefaultDisc2, DefaultDisc3, AnesMulti1, AnesMulti2, AnesMulti3)
-
SELECT
-
(@AddID, LastName, FirstName, MiddleInitial, MedicalTitle, DateOfBirth, SSN, Gender,
-
Specialty1, Specialty2, FacilityBased, CredApproval, FeeSchedID1, FeeSchedID2, FeeSchedID3,
-
DefaultDisc1, DefaultDisc2, DefaultDisc3, AnesMulti1, AnesMulti2, AnesMulti3 FROM Inserted)
-
-
END
-
GO
-
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
4 2101
Another note is that this trigger is being used to insert a record into a view that combines the fields for both tables.
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
Ck,
Thanks; that was a rookie mistake. I did that but I'm still getting the other errors; any ideas?
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |
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,...
|
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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
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...
| |