Click here to Skip to main content
15,906,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
0 Hi,

I have two tables

Stock table and Order Items Table

The Stock Table contains a Sold_Stock field

The Order Items Table contains a quantity field

both tables are linked by an Item_ID (Primary key in the Stock Table and Foreign key in the Order Items Table)

I want to know how to write a formula in Sql Server 2008 on the Sold_Stock field so that whenever a record is inserted into the Order Items Table the quantity field value will get added to the Sold_Stock field in the Stock Table.

I know how to write formulas within a table but i have no idea to reference another table's column. Can anyone please help me out!

Thanks in advance

Mirfath
Posted
Comments
__TR__ 23-Nov-12 6:47am    
You can do this using triggers. This article helps you understand triggers
Triggers -- Sql Server[^]
Corporal Agarn 23-Nov-12 13:51pm    
I had the same thought.

1 solution

Trigger is best for this problem
 
Share this answer
 

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