Convert a positive decimal number, negative

4

I have the following query :

Valor1 = '200.000,00';

select Valor1 from TB1

Is there a function that converts a positive number to negative?

    
asked by anonymous 18.12.2015 / 10:56

2 answers

8

If you just want to select the values as negative, it looks like this:

select -CAST(REPLACE(REPLACE(Valor1, '.', ''), ',', '.') AS DECIMAL(10, 2)) from TB1

or

select -1 * REPLACE(REPLACE(Valor1, '.', ''), ',', '.') from TB1

If you want to change them in the table:

update TB1 set Valor1 = -1 * REPLACE(REPLACE(Valor1, '.', ''), ',', '.')

Pure mathematics, except for conversion. It would be good to rethink whether to use a type that requires conversion. Look at the confusion you will have to make in every consultation. It's best to start fixing these things to avoid future problems.

    
18.12.2015 / 11:01
0

Multiply by -1 that the multiplication result is the negative number.

select Valor1 * -1 AS Valor1 from TB1

    
18.12.2015 / 18:30