Subtraction between two fields of same value does not give zero- SQL Server

0

Someone could explain me: I made a join between two tables. Both bring the same value in their fields. And when I subtract one value minus the other, it does not give zero. How is this possible?

E1_SALDO  = 990,42

BAIXZ0    = 990,42

SUBTRACAO = 990,42 - 990,42 = 1,13686837721616E-13
    
asked by anonymous 09.10.2018 / 15:13

1 answer

1

This happens because the SQL Server decimal pattern uses '.' in place of ','

To correct your calculation just use the REPLACE function.

link

This should solve your problem:

declare @E1_SALDO   decimal = REPLACE('990,42', ',', '.'),
        @BAIXZ0     decimal = REPLACE('990,42', ',', '.')

select @E1_SALDO - @BAIXZ0
    
09.10.2018 / 15:58