I have an UPDATE trigger on the column STATUS. This column takes int. Instead of firing on every change, I want it to fire only when STATUS changes to 3, 4 or 6.
How can I achieve this? I'm guessing I have to extend this rule?
IF ( UPDATE (STATUS) )
USE [TEST]
GO
/****** Object: Trigger [dbo].[PROJECT_StatusUpdate] Script Date: 27-9-2023 16:47:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[PROJECT_StatusUpdate] ON [dbo].[PROJECT]
AFTER UPDATE
AS
IF ( UPDATE (STATUS) )
BEGIN
SET NOCOUNT ON;
INSERT [IT].[dbo].[ProjectStatusLog]
(ProjectNO, OldStatus, NewStatus, DateChanged)
SELECT
d.PROJECTNO,
d.STATUS,
i.STATUS,
GETDATE()
FROM inserted i
FULL JOIN deleted d ON d.OBJECTID = i.OBJECTID
END;
2条答案
按热度按时间h79rfbju1#
You don't need to use
FULL JOIN
,INNER JOIN
is fine. Place the required checking condition in theWHERE
clausebgibtngc2#
Thanks for the help. Got it working.