sql存储过程,减去或加到值 [英] sql stored procedure, subtract or add to value

查看:104
本文介绍了sql存储过程,减去或加到值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许我对在Google中搜索的内容有些不解.

我的问题是这样定义的:
我有桌子在切断. 2列:productNr

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.

Select-query to get curQuantity.
newQuantity = curQantity + (added or subtractet)
update-query to set newQantity.


我当时想应该可以在一个sql表达式中做到这一点?
从而提高了我们程序的效率.


I was thinking that this should be possible to do in one sql expression?
And therefor improve the efficiency of our program.

推荐答案

是:
DECLARE @OrigQuantity INT
SELECT TOP 1 @OrigQuantity = curQuantity FROM Products WHERE Id=3
UPDATE Products SET curQuantity = @OrigQuantity - 2 WHERE Id=3
SELECT @OrigQuantity 


这篇关于sql存储过程,减去或加到值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆