Doubt - SQL Server Query

0

How do I get the sql server to get the records longer than 10 days from the current date, ie in the current month, I want to get all the records prior to 01-08. I tried it that way, but it did not return anything.

SELECT
S.SolID [Chamado],
UC.UsuNome [Cliente],
C.Descricao [Curva ABC],

CONVERT(DATE,S.SolData,103) [Data de Abertura]
FROM Solicitacao S
LEFT JOIN Usuario UC on UC.Usuid = S.UsuIDCliente
LEFT JOIN CurvaABC C on C.CurvaID = UC.CurvaID

LEFT JOIN Usuario U on U.UsuID = S.UsuIDResponsavel
WHERE S.SolStatus <> 9 and CONVERT(DATE,S.SolData,103) = getdate() - 10
and U.UsuIDGrupo = 1151
    
asked by anonymous 10.08.2017 / 19:55

2 answers

2

You can use the DATEDIFF function to perform this comparison. For this, I am considering that the SolData field is of type DATETIME.

Basically, just put this in your WHERE clause.

DATEDIFF(dd,S.SolData,getdate()) >= 10

It's the same thing to do:

S.SolData <= getdate() - 10

However, the advantage of DATEDIFF is that you can specify that the date range to be compared is Day, Month, Year, Hour, Minute, Second, etc.

In the above case, the DATEDIFF is returned to the difference, in days (parameter dd ), between SolData and the current date of the Bank. If this difference is >= to 10 days, then the records that they serve will be returned.

    
10.08.2017 / 21:25
0

Good afternoon @Renan Bessa

  

How do I in the sql server to get the records greater than 10   days from the current date

To TAKE ALL DATES GREATER THAN 10 DAYS would be:

SELECT * FROM clinica.teste
where
(data_nascimento > curdate()+10);
select * from teste;

Current date = CURDATE (); Home Current date + 10 days = CURDATE () + 10; Home To get the smaller ones, just reverse the > Home I hope I understood your question :)
Hugs

    
10.08.2017 / 20:27