GeoVIP
GeoVIP

Reputation: 1564

Increment / Decrement in stored procedure T-SQL

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

Upvotes: 4

Views: 8090

Answers (2)

user7591039
user7591039

Reputation: 1

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

Upvotes: 0

Himanshu
Himanshu

Reputation: 32602

Use simple update query like this:

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

See this SQLFiddle

Upvotes: 3

Related Questions