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
 Join a table to itself

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2008-07-22 : 11:36:24
Have the following code below and I think the my solution is to join the inserted table to itself, but I do not remember how I would do that.

Could someone please refresh my memory?

I'm trying to update two calculated fields and the code below does not seem to work.
ALTER TRIGGER [UPDATEEXTRA7WITHCUSTTYPE2] ON [dbo].[OrderRebateHistory] 
after INSERT
AS

begin
update OrderRebateHistory
set rebate_amt = (inserted.price*(.01*inserted.rebate_pct)),
ext_rebate = (inserted.price*(.01*inserted.rebate_pct)*inserted.qty_to_ship)
from inserted
where inserted.ord_type = OrderRebateHistory.ord_type and inserted.ord_no = OrderRebateHistory.ord_no and
inserted.item_no = OrderRebateHistory.item_no and inserted.line_no = OrderRebateHistory.line_no
end

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-07-22 : 11:42:59
You should simply use a computed column for this, not a trigger.

see: http://balajiramesh.wordpress.com/2008/06/05/computed-columns-in-sql-server-2005/

for an example. Much easier, quicker, shorter.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

Vack
Aged Yak Warrior

530 Posts

Posted - 2008-07-22 : 12:05:10
I do not follow what was on the link. May as well been in chinese.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-22 : 13:49:10
duplicate

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=107153
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-22 : 13:50:24
quote:
Originally posted by Vack

I do not follow what was on the link. May as well been in chinese.


the posted link by Jsmith clearly explained what you wanted.
Go to Top of Page
   

- Advertisement -