Tuesday, 25 August 2009

Date Stamp trigger - SQL

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [trg_test]
ON [dbo].[JobLog]
AFTER UPDATE
AS
BEGIN
IF

UPDATE(JobLogSignOff)
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.

SET NOCOUNT ON
;
UPDATE
JobLog
SET JobLogSignOffTimeStamp = GETDATE()
WHERE
JobLogID in (SELECT JobLogID FROM inserted)
-- Insert statements for trigger here
END
END

No comments: