Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Maybe i have a little brainfreeze on what to search for in google.

My question is defined like this:
I have table at sever. 2 columns: productNr,
curQuantity<br />

Troughout the day i have program which makes rapid changes to this table after user has decided to add or subtract to this amount.
Our current setup is like this.
SQL
Select-query to get curQuantity.
newQuantity = curQantity + (added or subtractet)
update-query to set newQantity.

I was thinking that this should be possible to do in one sql expression?
And therefor improve the efficiency of our program.
Posted
Updated 20-May-12 0:23am
v2

1 solution

Yes:
SQL
DECLARE @OrigQuantity INT
SELECT TOP 1 @OrigQuantity = curQuantity FROM Products WHERE Id=3
UPDATE Products SET curQuantity = @OrigQuantity - 2 WHERE Id=3
SELECT @OrigQuantity 
 
Share this answer
 
Comments
Maciej Los 20-May-12 6:24am    
Good work, 5!

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