views:

141

answers:

4

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
+1  A: 

Can't you just multiply it by -1?

Chris B.
Yep - that's what i was looking for.Obvious i know, but its too early in the morning to be writing T-SQL without adequate caffeine.Thanks Chris.
RPM1984
A: 

Multiply @Points by -1 in that certain scenario.

slugster
A: 

I always do 0 - @Points. It was this way in some code I inherited. "A foolish consistency..."

uncle brad
that would work too.any difference between between doing it that way and multiplying by -1?
RPM1984
There is no significant difference between `0 - @Points` and `-1 * @Points` in SQL Server 2008.
uncle brad
Actually `-@Points` works fine in 2008.
uncle brad
A: 

lolz.. i thot of subtracting it with multiple of 2 ie x-2x

sajad