This is my SQL statement that works using datediff..............
SELECT SUM(b134_nettpay) AS Total, b134_rmcid, b134_recdate
FROM B134HREC
WHERE datediff (dd, '2006-05-05', getdate()) > 90
GROUP BY b134_rmcid, b134_recdate
ORDER BY b134_recdate DESC, b134_rmcid
I need to Replace the Hardcoded date '2006-05-05' with MAX(b134_recdate) like so.........
SELECT SUM(b134_nettpay) AS Total, b134_rmcid, b134_recdate
FROM B134HREC
where datediff (dd, MAX(b134_recdate), getdate()) > 90
GROUP BY b134_rmcid, b134_recdate
ORDER BY b134_recdate DESC, b134_rmcid
But i get this Error message...........
"An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference."
Any idea how to fix my SQL Statement?
Thanks in advanced! Etienne