troubleshooting Question

Update Trigger inserts data into 2 tables with 2nd insert using data from 2 tables

Avatar of tammieR
tammieR asked on
Microsoft SQL Server
5 Comments1 Solution274 ViewsLast Modified:
Here is what I have.  I have 3 Tables. When a certain field in Table A gets updated to Yes I have an udpdate trigger that has an insert statement that puts the updated row (row that a field got changed to yes) into Table B. Now I need to insert some of the data from the updated row in Table A and I need the UniqueID of the newly inserted Row in Table B and insert the data from Table A and Table B into Table C.

Here is what I have so far and it work good. It inserts data from the row that was update in Table A into Table B:

CREATE TRIGGER ToInsertRow ON TableA
AFTER UPDATE
AS
IF UPDATE(YesNoColumn)
BEGIN
INSERT INTO  TableB(
      Column1,
      Column2)
SELECT inserted.Column1, inserted.Column4
FROM inserted
WHERE inserted.YesNoColumn = 'Yes'
END

Thanks in Advance
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros