Link to home
Start Free TrialLog in
Avatar of rudyflyer
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.
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Lose the IF and use a where clause:

UPDATE Table
SET field= (field * -1)
Where SIGN(field) = -1
update table
set field = field * -1
where field < 0
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial