Link to home
Start Free TrialLog in
Avatar of stephenlecomptejr
stephenlecomptejrFlag for United States of America

asked on

Need help changing a Microsoft Access select query having to show only dated records more than 7 days old.

Need help with changing Microsoft Access SQL query to show date entered records that are more than 7 days old.
So far a lot of suggestions have not really worked for me at this link so I decided to add this as a new question:

https://www.experts-exchange.com/questions/29140112/Need-help-with-creating-a-cross-tab-report-that-would-identify-the-last-date-an-employee-entered-time.html?headerLink=workspace_answered_questions

I know must include : HAVING but no data is coming up with records that do have dates more than 7 days old.

SELECT Employees.EmployeeID, Employees.UserName, Max(TimeSheetData.DateEntered) AS MaxOfDateEntered
FROM Employees LEFT JOIN TimeSheetData ON Employees.EmployeeID = TimeSheetData.EmployeeID
GROUP BY Employees.EmployeeID, Employees.UserName
HAVING DateValue(Max(TimeSheetData.DateEntered)) > DateAdd("d",7,Date())
ORDER BY Max(TimeSheetData.DateEntered) DESC;

Open in new window


When I try the above I get DataType mismatch in criteria expression.

If I try below- I get no errors but I also get no records which can't be right cause 80% are over 7 days old

SELECT Employees.EmployeeID, Employees.UserName, Max(TimeSheetData.DateEntered) AS MaxOfDateEntered
FROM Employees LEFT JOIN TimeSheetData ON Employees.EmployeeID = TimeSheetData.EmployeeID
GROUP BY Employees.EmployeeID, Employees.UserName
HAVING Max(TimeSheetData.DateEntered)>DateAdd("d",7,Now())
ORDER BY Max(TimeSheetData.DateEntered) DESC;

Open in new window

Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Try with:

HAVING DateDiff("d", Max(Nz(TimeSheetData.DateEntered, Date())), Date()) > 7

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stephenlecomptejr

ASKER

Dale's was the one that worked correctly.  Appreciate all the replies.