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
 Trigger Question Calculation

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2008-07-23 : 17:23:32
Have two tables:
OrderRebate
OrderRebateHistory

Both have same fields.
Keys are:
ord_type
ord_no
line_no
item_no
inv_no

Two 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_ship


Everything 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 OrderRebate
set 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_no
where inserted.ord_type = OrderRebate.ord_type and inserted.ord_no = OrderRebate.ord_no and
inserted.line_no = OrderRebate.line_no
end


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

Posted - 2008-07-23 : 17:29:17
quote:

it doesn't seem to work.



Could you elaborate?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-24 : 03:59:17
quote:
Originally posted by Vack

Have two tables:
OrderRebate
OrderRebateHistory

Both have same fields.
Keys are:
ord_type
ord_no
line_no
item_no
inv_no

Two 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_ship


Everything 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 OrderRebate
set 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_no
where inserted.ord_type = OrderRebate.ord_type and inserted.ord_no = OrderRebate.ord_no and
inserted.line_no = OrderRebate.line_no
end


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
Go to Top of Page

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.
Go to Top of Page

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?
Go to Top of Page
   

- Advertisement -