TRS
TRS

Reputation: 490

Update error in trigger

I want to update some data column after inserting values. But it gives me some error. Please help me to fix this.

Msg 4104, Level 16, State 1, Procedure TriggerBonus, Line 20
The multi-part identifier "i.User_id" could not be bound.

The trigger:

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)

Upvotes: 0

Views: 86

Answers (1)

bhupendra patel
bhupendra patel

Reputation: 3179

Your update needs to be :

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

Upvotes: 1

Related Questions