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

时间:2021-04-18 16:39:51

I have a table with following fields:

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

ID , FirstName , LastName , Count , Amount

Need something like this code :

需要如下代码:

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

2 个解决方案

#1


4  

Use simple update query like this:

使用如下简单的更新查询:

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

See this SQLFiddle

#2


0  

UPDATE MST_SPR_donategifts SET Gift_Quantity = Gift_Quantity- @Gift_Quantity WHERE Gift_Code=@Gift_Code

更新MST_SPR_donategifts集Gift_Quantity = Gift_Quantity- @Gift_Quantity,其中Gift_Code=@Gift_Code

#1


4  

Use simple update query like this:

使用如下简单的更新查询:

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

See this SQLFiddle

#2


0  

UPDATE MST_SPR_donategifts SET Gift_Quantity = Gift_Quantity- @Gift_Quantity WHERE Gift_Code=@Gift_Code

更新MST_SPR_donategifts集Gift_Quantity = Gift_Quantity- @Gift_Quantity,其中Gift_Code=@Gift_Code