T-SQL: How to make a positive value turn into the equivalent negative value (e.g "10.00" to "-10.00"

Posted by RPM1984 on Stack Overflow See other posts from Stack Overflow or by RPM1984
Published on 2010-06-07T01:54:59Z Indexed on 2010/06/07 2:02 UTC
Read the original article Hit count: 242

Filed under:
|

Ok so i have a DECIMAL field called "Score". (e.g 10.00)

Now, in my SP, i want to increment/decrement the value of this field in update transactions.

So i might want to do this:

SET @NewScore = @CurrentScore + @Points

Where @Points is the value im going to increment/decrement.

Now lets say @Points = 10.00.

In a certain scenario, i want 10.00 to become -10.00

So the statement would be translated to:

SET @NewScore = @CurrentScore + -10.00

How can i do that?

I know its a strange question, but basically i want that statement to be dynamic, in that i dont want to have a different statement for incrementing/decrementing the value.

I just want something like this:

SET @Points = 10.00
IF @ActivityBeingPerformedIsFoo
BEGIN
   -- SET @Points to be equivalent negative value, (e.g -10.00)
END
SET @NewScore = @CurrentScore + @Points

© Stack Overflow or respective owner

Related posts about tsql

Related posts about stored-procedures