Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have two columns, Quantity and Value. I want Value to be relational to Quantity in the sense that if quantity goes up its value stays relational to it and also goes up. Any ideas how to do this? (SQL Server 2008)
Posted

Try using a TRIGGER[^] to find out if Quantity column is updated using UPDATE[^] and then update the Value column with the new manipulated value accordingly in the trigger.
 
Share this answer
 
Comments
Valery Possoz 12-Dec-11 9:37am    
You beat me to it! :) 5!
Nikil S 12-Dec-11 9:49am    
Thank you.
Hello,

One way to do this is to use a trigger.

Something like that:

SQL
Create Trigger UpdateData
On Table_1
After Insert, Update
As
Update Table_1 set Value = Quantity * 2;


Each time an update or insert will be performed, the trigger will be called, you can put what ever SQL you fancy in the trigger.

http://msdn.microsoft.com/en-us/library/ms189799.aspx[^]

Valery.
 
Share this answer
 
v2
Comments
WurmInfinity 12-Dec-11 9:39am    
Yeah that's awesome. Opens up loads of new possibilities too. Thanks a lot! x

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900