Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Question on using inserted in trigger

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2011-12-07 : 12:21:51

I'm getting the message:
Cannot use column prefix inserted. This must match the object in the update clause.

How do I create the trigger so that only inserted records get the exp_cost updated?


CREATE TRIGGER [UpdateCost1] ON [dbo].[SHIPDTL]
for INSERT
AS

update shipdtl
set inserted.exp_cost = poordlin.exp_unit_cost
from poordlin join inserted on poordlin.ord_no = inserted.s_ord_no and poordlin.line_no =
inserted.s_line_no and poordlin.item_no = inserted.s_item_no


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-07 : 12:27:44
[code]
CREATE TRIGGER [UpdateCost1] ON [dbo].[SHIPDTL]
for INSERT
AS

update s
set s.exp_cost = p.exp_unit_cost
from poordlin p
join inserted i
on p.ord_no = i.s_ord_no
and p.line_no = i.s_line_no
and p.item_no = i.s_item_no
join shipdtl s
on s.ord_no = i.s_ord_no
and s.line_no = i.s_line_no
and s.item_no = i.s_item_no
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -