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
 Update record after insert

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2008-05-30 : 09:17:54
Using trigger
want to update a field being inserted from another record in the same table.

the record being inserted I want to pull the bkjrcode from another record where the account = 1040 that also has the same ord# and inv# as the record being inserted.

Here is what I've tried with no luck.

create trigger [updategbkmut] on [dbo].[gbkmut]
after insert
as

update g1
set g1.bkjrcode = g2.bkjrcode
from gbkmut g1
inner join inserted i
on i.ord_no = g1.ord_no and i.inv_no = g1.inv_no
inner join gbkmut g2
on i.ord_no = g2.ord_no and i.inv_no = g2.inv_no
where i.freefield3 = 'Rebate' and g1.account = '1040'

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-30 : 10:26:59
Cant find any problem with the trigger code.Whats the error you're getting?
Go to Top of Page

Vack
Aged Yak Warrior

530 Posts

Posted - 2008-05-30 : 10:34:34
No error. Its just not updating the fields.
Go to Top of Page
   

- Advertisement -