Reputation: 21
I have this table in SQL called 'account' that looks like this:
Debits Credits
-22 0
-1 -1
-5 0
0 -9
-13 -4
I want all the values to be positive, but for the account to still make sense at the end. So all the negative values in the Debits column will become positive in the Credits column so that it looks like the table below. How do I go about this? The values in both columns are floats.
Debits Credits
0 22
1 1
0 5
9 0
4 13
Thanks!
Upvotes: 1
Views: 222
Reputation: 44991
Use the unary minus operator for a cleaner syntax
UPDATE yourTable
SET
Credits = -Debits,
Debits = -Credits;
Upvotes: 0
Reputation: 522797
Your sample data implies that the logic is to swap and negate the debits and credits values:
UPDATE yourTable
SET
Credits = -1.0 * Debits,
Debits = -1.0 * Credits;
Upvotes: 1