触发我的假期

时间:2012-03-31 09:11:53

标签: sql

Goodday我想写一个触发器,它将返回我休假日的总和。我写了下面的触发器,但得到了错误.Ambiguous列名'leaveEarned'.Ambiguous列名'leaveTaken'。我怎么能写得更好,谢谢

    CREATE TRIGGER dbo.tgr_update_Leavesum ON dbo.diary  
     FOR INSERT, UPDATE  
      AS  
      BEGIN --Trigger   
      IF UPDATE(LeaveSum)      
       UPDATE Diary  
        SET LeaveSum =  (select sum(leaveEarned) )- (select sum(leaveTaken) )
           FROM Diary D INNER JOIN inserted ON D.DayId = inserted.DayId  

              END --Trigger  

1 个答案:

答案 0 :(得分:0)

尝试以下

CREATE TRIGGER dbo.tgr_update_Leavesum ON dbo.diary  
     FOR INSERT, UPDATE  
      AS  
      BEGIN --Trigger   
      IF UPDATE(LeaveSum)      
       UPDATE Diary  
        SET LeaveSum =  (select sum(inserted.leaveEarned) - sum(inserted.leaveTaken)
           FROM Diary D INNER JOIN inserted ON D.DayId = inserted.DayId ) 

              END --Trigger