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-07-23 : 17:23:32
|
Have two tables:OrderRebateOrderRebateHistoryBoth have same fields. Keys are:ord_typeord_noline_noitem_noinv_noTwo fields, rebate_amt and ext_rebate need to be calculated when a record is inserted into the orderrebatehistory.I need a trigger that will do this for me. I've tried calculated fields on the orderrebatehistory but that causes problems with all of my other triggers. and I don't have time to deal with those issues so I need to accomplish this through a trigger. My calcuations:rebate_amt = price*(.01*rebate_pct)ext_rebate = price*(.01*rebate_pct)*qty_to_shipEverything I seem to try just populates rebate_amt and ext_rebate with NULL. I have a trigger on the orderrebate table that works perfect.update OrderRebateset rebate_amt = (rebate.price*(.01*rebate.rebate_pct)),ext_rebate = (rebate.price*(.01*rebate.rebate_pct)*inserted.qty_to_ship)from inserted INNER JOIN cicmpy ON inserted.cus_no = cicmpy.debcode INNER join rebate on cicmpy.AccountTypeCode = Rebate.cd_tp_3_cus_type AND inserted.item_no = Rebate.item_nowhere inserted.ord_type = OrderRebate.ord_type and inserted.ord_no = OrderRebate.ord_no and inserted.line_no = OrderRebate.line_noend But for some reason if I apply the same logic to the trigger on the orderrebatehistory table it doesn't seem to work. Looking for any ideas on how I can accomplish this. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-24 : 03:59:17
|
quote: Originally posted by Vack Have two tables:OrderRebateOrderRebateHistoryBoth have same fields. Keys are:ord_typeord_noline_noitem_noinv_noTwo fields, rebate_amt and ext_rebate need to be calculated when a record is inserted into the orderrebatehistory.I need a trigger that will do this for me. I've tried calculated fields on the orderrebatehistory but that causes problems with all of my other triggers. and I don't have time to deal with those issues so I need to accomplish this through a trigger. My calcuations:rebate_amt = price*(.01*rebate_pct)ext_rebate = price*(.01*rebate_pct)*qty_to_shipEverything I seem to try just populates rebate_amt and ext_rebate with NULL. I have a trigger on the orderrebate table that works perfect.update OrderRebateset rebate_amt = (rebate.price*(.01*rebate.rebate_pct)),ext_rebate = (rebate.price*(.01*rebate.rebate_pct)*inserted.qty_to_ship)from inserted INNER JOIN cicmpy ON inserted.cus_no = cicmpy.debcode INNER join rebate on cicmpy.AccountTypeCode = Rebate.cd_tp_3_cus_type AND inserted.item_no = Rebate.item_nowhere inserted.ord_type = OrderRebate.ord_type and inserted.ord_no = OrderRebate.ord_no and inserted.line_no = OrderRebate.line_noend But for some reason if I apply the same logic to the trigger on the orderrebatehistory table it doesn't seem to work. Looking for any ideas on how I can accomplish this.
Didnt i suggest you to replace trigger with a calculated column?http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=107153 |
 |
|
|
Vack
Aged Yak Warrior
530 Posts |
Posted - 2008-07-24 : 09:06:55
|
| I did replace it with a calculated column but then that caused all of my other triggers that were tied to that table to no longer work. So I had to change that back. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-24 : 09:46:30
|
quote: Originally posted by Vack I did replace it with a calculated column but then that caused all of my other triggers that were tied to that table to no longer work. So I had to change that back.
didnt get that. Can you give some background info on what you're trying to achieve? |
 |
|
|
|
|
|