FamousMortimer
asked on
SQL Trigger Help - Update another table after INSERT
Hi Experts, I need a trigger to update table tScheduleRequests when an INSERT is performed on table AR1. This is actually my first attempt at a trigger and I know it's not too difficult, but I need a push in the right direction... This is what I have so far using the SQL template as a guide:
Thanks in advance
-Jeremy
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER trUpdateScheduleRequestsA1
ON dbo.AR1
AFTER INSERT
AS
IF EXISTS (SELECT OrderNumber, SchDte FROM Schedule.dbo.tScheduleRequests, inserted WHERE OrderNumber=Ordno)
BEGIN
SET NOCOUNT ON;
UPDATE Schedule.dbo.tScheduleRequests
SET ScheduledDate=i.SchDte
INNER JOIN inserted As i
ON tScheduleRequests.OrderNumber=i.Ordno
END
GO
Thanks in advance
-Jeremy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're welcome.
The INNER JOIN automatically prevents unwanted rows from being UPDATEd.
The INNER JOIN automatically prevents unwanted rows from being UPDATEd.
ASKER