我想在插入值后更新一些数据列。但它给了我一些错误。请帮我解决这个问题。
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)
答案 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)