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.
Author |
Topic |
Vack
Aged Yak Warrior
530 Posts |
Posted - 2008-05-29 : 16:07:02
|
Need to update a field on a record that is getting inserted based off of an existing record in table. if the record being inserted has a value of Rebate in freefield3 then update bcode with bcode from another record where the other record has teh same order number and invoice number as the inserted record and also the existing record as an account number of 1040. Here is what I have so far and it doesn't seem to be working.CREATE TRIGGER [UPDATEEGBKMUTREBATERECORDS] ON [dbo].[GBKMUT] AFTER INSERTASBEGINUPDATE GBKMUTSET GBKMUT.bcode = GBKMUT.bCODEFROM INSERTED JOIN GBKMUT ON INSERTED.ord_no = GBKMUT.ord_no ANDINSERTED.inv_no = GBKMUT.inv_noWHERE INSERTED.FREEFIELD3 = 'Rebate' AND INSERTED.ord_no = GBKMUT.ord_no ANDINSERTED.inv_no = GBKMUT.inv_noEND |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-29 : 16:16:28
|
I think you need to join to GBKMUT again.Maybe this:UPDATE g1SET bcode = g2.bCODEFROM GBKMUT g1INNER JOIN inserted iON i.ord_no = g1.ord_no AND i.inv_no = g1.inv_noINNER JOIN GBKMUT g2ON i.ord_no = g2.ord_no AND i.inv_no = g2.inv_noWHERE i.FREEFIELD3 = 'Rebate' AND g1.AccountNumber = 1040Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
|
|
|