In T-SQL you can use a CASE
statement when doing a SELECT
to determine what sort of data you want to return. I'd like to do something like that, but not in a SELECT
statement, but instead in an UPDATE statement. I don't know if this is the correct format or not, but hopefully you'll get the idea from this.
Here's what I'm trying to do:
CREATE PROCEDURE spSomePS
@Number1 int,
@Number2 int,
@Amt money
AS
BEGIN
UPATE SomeTable
CASE @Number1 +1 = @Number2
MoneyColumn = MoneyColumn - @Amt
ELSE
MoneyColumn = MoneyColumn + @Amt
END -- end the CASE statement
Will that so what I'm trying to do or is there another syntax?
You can use CASE
expression in UPDATE
statement as in SELECT
statement.
CREATE PROCEDURE spSomePS
@Number1 int,
@Number2 int,
@Amt money
AS
BEGIN
UPATE SomeTable
SET MoneyColumn =
CASE WHEN @Number1 +1 = @Number2
THEN MoneyColumn - @Amt
ELSE MoneyColumn + @Amt
END -- end the CASE statement
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments