1
Guys, as I am new to SQL, I need a help. I need to bring only the records that have not been moving for more than two days.
The query below is bringing everyone without this condition. I even ran a test using Datediff, but I’m not sure if that’s what it was.
Bringing all the records this condition
Qtde Data
5000 18-07-2017
5001 18-07-2017
5002 25-07-2017
However, it was only to bring those of the 18th, as it is more than 2 days before today’s date. Below is the query I tried to do.
SELECT DISTINCT
S.SolID AS [Qtde - Chamados em Pausa],
MAX(CONVERT(DATE,T.TraData,103))
FROM Solicitacao S
LEFT JOIN Usuario U ON U.UsuID = S.UsuIDResponsavel
LEFT JOIN Tramite T ON T.SolID = S.SolID
WHERE S.VencimentoPausado = 1 AND
T.TraData < DATEDIFF ( DAY ,2, getdate())
group by s.SolID
Show Ball Guy. I do not put the structure of the tables because it is too big and some case is impossible to put here, but it worked. Thanks!
– Renan Bessa
Good that helped, about the size, you can post the DDL, and always put the code between two acute accents ` or after four spaces for it to be formatted, size of the questions, I believe that is no problem. You can also use Sqlfiddle, because it helps a lot when analyzing the code and understanding the need.
– Rovann Linhalis