4

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

ID , FirstName , LastName , Count , Amount

需要这样的代码:

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

2 回答 2

4

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

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

看到这个 SQLFiddle

于 2013-05-30T10:20:16.953 回答
0

更新 MST_SPR_donategifts 设置 Gift_Quantity = Gift_Quantity-@Gift_Quantity WHERE Gift_Code=@Gift_Code

于 2017-02-20T04:29:44.147 回答