rudyflyer
asked on
SQL converting a negative number to positive
Hello,
In our SQL Server database we have money values that are negative. But I need to convert all negative values to positive values. I am using the following code in Query Analyzer:
--Convert all negative numbers to positive numbers
IF (SELECT field FROM table) < 0
UPDATE Table
SET field= (field * -1)
But I get the following error:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
What am I doing wrong? Or is there a better way to get the absolute value of a negative number?
Thanks in advance.
In our SQL Server database we have money values that are negative. But I need to convert all negative values to positive values. I am using the following code in Query Analyzer:
--Convert all negative numbers to positive numbers
IF (SELECT field FROM table) < 0
UPDATE Table
SET field= (field * -1)
But I get the following error:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
What am I doing wrong? Or is there a better way to get the absolute value of a negative number?
Thanks in advance.
update table
set field = field * -1
where field < 0
set field = field * -1
where field < 0
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
UPDATE Table
SET field= (field * -1)
Where SIGN(field) = -1