0
I have the following consultation:
select DATEDIFF("D",DtVencimento,DtBaixa) as atraso
from Entrada
where Id='1' and DtEmissao >='01/01/2020'
and DtEmissao <='01/12/2020'
and ((VlBaixado is not null and VlBaixado != 0)
and DtBaixa is not null)
and DATEDIFF("D",DtVencimento,DtBaixa) < 0;
When it returns me more than one line I need to identify the highest and lowest value. For example, in the result below:
delay |
---|
-6 |
-10 |
-20 |
I need to identify the minor (-20
) and the greatest (-6
) value.
Can someone help me return these values in a query in SQL Server?
You want the values to be returned in separate lines?
– imex
Not necessarily, I just wish I could get one with the maximum and minimum values. I’m not sure how to do.
– Robson Cabral
If it can be on the same line then you can use the functions Min and Max
– imex
Thanks @Imex I already tried to use, but the way I do was not solving.
– Robson Cabral
@Robsoncabral Be careful when reporting the date as literal without associating what the date format is. For example, "01/12/2020" is December 1 or January 12? SQL Server can interpret in different ways, depending on the session’s DATEFORMAT. Details in the article The dangers of automatic data type conversion -> https://portosql.wordpress.com/2018/10/25/os-perigos-da-conversao-implicita-1/
– José Diz
Opa @Josédiz I am aware of this, the original query will be with the date functions picking from today to 12 months ago. Thanks for the tip, it is very important to stay attend to this even if the result does not come out as it should.
– Robson Cabral