触发错误Microsoft SQL Server Studio 2018

时间:2019-09-26 11:44:15

标签: sql-server tsql database-trigger

CREATE TRIGGER UpdateSafeBatch 
   ON  ClientService 
   AFTER UPDATE
AS 
BEGIN
    IF NEW.Closed != OLD.Closed THEN
        UPDATE SafeBatch SET SafeBatch.TotalVisa=SafeBatch.TotalVisa+ClientService.TotalVisa,
                     SafeBatch.TotalCash=SafeBatch.TotalCash+ClientService.TotalCash,
                     SafeBatch.Total=SafeBatch.Total+ClientService.Total,
        WHERE SafeBatch.Id=ClientService.SafeBatchId

    END
GO

1 个答案:

答案 0 :(得分:0)

CREATE TRIGGER UpdateSafeBatchAbdallah 
   ON  ClientService 
   AFTER UPDATE
AS 
BEGIN
    --IF NEW.Closed != OLD.Closed THEN

        UPDATE SafeBatch SET TotalVisa+=inserted.TotalVisa,
                     TotalCash+=inserted.TotalCash,
                     Total+=inserted.Total
                      FROM inserted
        WHERE SafeBatch.Id=inserted.SafeBatchId and inserted.Closed=1

END
GO