更新数据库表旧值+数字 [英] Update db table old values+number

查看:60
本文介绍了更新数据库表旧值+数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些有关更新数据库表的帮助.
我有一个带有int值的表,我想更新它
因此每个值都将是其当前值+我选择的某个数字.
问题是如何有效地获取当前号码?
在此先感谢:)

Hi, I need some help in updating a database table.
I have got a table with int values and i want to update it
so as each value will be its current value + some number i choose.
the question is how i get the current number efficiently?
thanks in advance :)

推荐答案

DECLARE @ProductID INT
DECLARE @HitCount INT
DECLARE @UPDATEHIT CURSOR
SET @UPDATEHIT = CURSOR FOR
 SELECT ProductID FROM Product
OPEN @UPDATEHIT 
FETCH NEXT
 FROM @UPDATEHIT INTO @ProductID
WHILE @@FETCH_STATUS = 0
 BEGIN
 UPDATE Production.Product
  SET HitCount =(Select HitCount+1 From Product Where ProductID=@ProductID)
 Where ProductID=@ProductID 

FETCH NEXT
FROM @UPDATEHIT INTO @ProductID
 END
CLOSE @UPDATEHIT 
DEALLOCATE @UPDATEHIT 


Hw关于以下内容:
Hw about something like this:
update table1 set value=value+number where id=1



http://www.w3schools.com/sql/sql_update.asp [ http://msdn.microsoft.com/en-us/library/ms177523.aspx [ ^ ]

最好的问候
Espen Harlinn



http://www.w3schools.com/sql/sql_update.asp[^]

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

Best regards
Espen Harlinn


thx,通过更新table1设置值+ =''num''进行求解,其中id = 1
thx, solved by update table1 set value+=''num'' where id=1


这篇关于更新数据库表旧值+数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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