Decimal rank Sql server

1

Hello good day I want to know how I can make a condition I have this problem when in a query rest field1-field2 in the condition I must bring only when there are differences, however there is a difference sometimes I get 0.01 or -0.01 if that comes out as a result I ignore it I have the query as follows:

SELECT CAMPO1-CAMPO2 FROM RESTA WHERE (CAMPO1-CAMPO2)>0

I want the query that brings me if the rent was 0 difference but if there is a range of 0.01 or negative I ignore it in the query, I did it using cast to work with integers but I do not serve

SELECT CAST((CAMPO1-CAMPO2) AS INT) FROM RESTA WHERE CAST((CAMPO1-CAMPO2) AS INT)>0

someone to help me with another way of doing it

    
asked by Javier Solis 29.11.2018 в 02:57
source

1 answer

1

Use the absolute value ABS of the difference to filter and CAST to discard the decimals

SELECT CAST(CAMPO1 - CAMPO2 AS INT) 
FROM RESTA 
WHERE ABS(CAMPO1 - CAMPO2) > 0.01
    
answered by 29.11.2018 / 03:07
source