tags:

views:

117

answers:

4

Someone entered a ton of numeric data into a table with the sign backwards.

Is there a clean way to flip the sign in the numeric column with a SQL statement?

+5  A: 
update my_table
  set amount = -amount
  where <whatever>
Ray
+2  A: 

It should be straightforward.

update table set column = -column;
Kyle Butt
+1  A: 

UPDATE [table] SET [column]=[column]*(-1)

You can add a WHERE clause as needed to limit which rows you are flipping signs on.

Matt
A: 
UPDATE MyTable
SET amount = -amount
WHERE amount = ABS(amount)

By including the amount = ABS(amount) clause you prevent unnecessary log activity and index maintenance. It's always a good idea to only update the rows that actually need it.

harschware
this will only make all amounts positive and not swap the positives to negatives.
No Refunds No Returns
Updated. Thanks for the check.
harschware