更新触发器中的错误

时间:2012-06-01 03:56:38

标签: sql sql-server triggers

我想在插入值后更新一些数据列。但它给了我一些错误。请帮我解决这个问题。

  

Msg 4104,Level 16,State 1,Procedure TriggerBonus,Line 20
  无法绑定多部分标识符“i.User_id”。

触发器:

CREATE TRIGGER [dbo].[TriggerBonus] ON [dbo].[Bonus]
FOR INSERT
AS
DECLARE @rcnt int 
SELECT @rcnt = @@rowcount

IF(SELECT COUNT(*) FROM Bonus,inserted WHERE Bonus.Tpv = inserted.Tpv)!=@@rowcount

/* Cancel the insert and print a message.*/
      begin
      rollback transaction 
      end  

/* Otherwise, allow it. */
else

UPDATE Bonus
SET Subdealers_Id=('user')
WHERE (User_id = i.User_id)

1 个答案:

答案 0 :(得分:1)

您的更新需要:

UPDATE Bonus
SET Subdealers_Id=('user')
from inserted i inner join Bonus 
on {put your join here}
WHERE (User_id = i.User_id)