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 |
|
dhh166
Starting Member
2 Posts |
Posted - 2012-06-20 : 06:27:48
|
| Hello All,I have a table for 'products', and table for 'sold' which I want to store the sold products, I want the 'qantity' column for'products' table to be edited automatically when I put value for 'quantity' col of 'sold' table ex: I have 10 pens and I sold 4 pens, when I record 4 pens in 'sold' table I want 'quantity' of 'products' to change automatically to '6' |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2012-06-20 : 13:56:19
|
| It's really not a good design to try to maintain an [inStock] quantity column right in your product table. One way to mimic an inventory system is to present the real-time quantity only when you need to present it - by returning the (sum of items purchased) minus the (sum of items sold). The code for that can be in a function or stored procedure.But to answer your question you could achieve what you described by performing the update to your [product] table from within a trigger on your [sold] table.Be One with the OptimizerTG |
 |
|
|
|
|
|