Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with an update trigger.

Status
Not open for further replies.

rarubio1

Programmer
Jan 25, 2002
64
US
I have written the following trigger to update the status field of a record, when the record is updated. Now I have to rewrite the trigger so that it only updates that status when the record is closed. Can someone please help me with the syntax for this conditional trigger?

The following is a sample of the current trigger:

CREATE TRIGGER trgUpdateStatus ON [dbo].[SOWork]
FOR UPDATE AS

BEGIN
Update tblWorkOrderDtl
Set Status = U.Status
FROM tblWorkOrder W, INSERTED U
WHERE U.OrdNbr = W.OrdNbr
AND U.LineItem = W.LineItem
END



Thanks!
RR :)
 
Code:
CREATE TRIGGER trgUpdateStatus ON [dbo].[SOWork] 
FOR UPDATE AS

BEGIN

   Update tblWorkOrderDtl
   Set Status = U.Status
   FROM tblWorkOrder W, INSERTED U
   WHERE U.OrdNbr = W.OrdNbr
      AND U.LineItem = W.LineItem
      AND u.Status = 'Closed' /*This should do the trick*/
END

Denny

--Anything is possible. All it takes is a little research. (Me)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top