December 10, 2004 at 3:52 am
Is there a function within SQL to convert any negative values to positive and the positive ones to negative?
Thanks
December 10, 2004 at 4:40 am
I don't know about a function but just multiply by -1.
For example:
update InvoiceDtl set UnitPrice = UnitPrice * -1
December 10, 2004 at 6:38 am
That'll work. ta
December 10, 2004 at 6:44 am
Actually if you only want ONLY positive values you'd be better off doing something like this :
Select ABS(MyCol) from dbo.MyTable
December 10, 2004 at 12:06 pm
December 10, 2004 at 12:25 pm
Why????
As Tyson said, just multiply by -1.
positive values become negative ( 1 * -1 = -1).
negative values become positive (-1 * -1 = 1).
Thats what the original request was for!
No need for conditional logic, and abs() only provides the absolute value which is always positive, not what was requested.
Steve
December 13, 2004 at 12:18 pm
I can't believe that I see this question for the second time. I feel obligated to quote the response I wrote some time ago, in another group:
INSERT INTO Numbers VALUES (0)
INSERT INTO Numbers VALUES (20)
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply