I'm developing a SQL Server procedure, which lists two tables:
WhereaprocesshasN-statements,Ineedtoreturnthefollowingdata:allProcessNumbersthatarewiththeIrrecuperavel(int)=1
columnandthe"last" date entered in the Process table for that% Process_Code% is DataAnda(date)
months.
SELECT
A.NumeroProcesso, MAX(A.DataAnda)
FROM Andamento AS A LEFT OUTER JOIN Processo AS P
ON A.NumeroProcesso = P.NumeroProcesso
WHERE
(P.Irrecuperavel = 1) AND
(DATEDIFF(MONTH, A.DataAnda, GETDATE()) >= 6)
GROUP BY A.NumeroProcesso
My procedure returns but does not filter for the longest time.