创建一个与columnA(日期类型)更新时相同的触发器ColumnB(日期类型)应更新为8天,并且不包括周末。 下面是我的SQL查询,请帮忙。 谢谢, 桑迪普
create TRIGGER Test
ON TableName
AFTER INSERT,UPDATE
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
IF UPDATE([Column A])
BEGIN
UPDATE [dbo].[TableName]
SET [Column B]= dateadd(day,8,i.[Column A])
FROM inserted i
INNER JOIN [TableName] t ON i.ID=t.ID
LEFT JOIN deleted d ON i.ID=d.ID
WHERE d.ID IS NULL AND i.[Column A] IS NOT NULL -- Row was inserted
OR d.ID IS NOT NULL -- Row was updated
END
END
GO