存储过程T-SQL中的递增/递减

时间:2013-05-30 10:17:14

标签: sql sql-server tsql

我有一个包含以下字段的表格:

ID , FirstName , LastName , Count , Amount

需要类似这样的代码:

IF EXISTS (SELECT * FROM [myDB] WHERE @ID = [ID])
set [count] = [count] + 1 and [Amount] = [Amount] - 1

2 个答案:

答案 0 :(得分:4)

使用这样的简单更新查询:

UPDATE myDB
SET [count] = [count] + 1
, [Amount] = [Amount] - 1
WHERE ID = @ID

请参阅this SQLFiddle

答案 1 :(得分:0)

更新MST_SPR_donategifts     SET Gift_Quantity = Gift_Quantity- @Gift_Quantity     在哪里Gift_Code = @ Gift_Code