I am having a problem limiting my query results to a related table value.
SELECT Roster.UserID, Roster.[WM DOH], Round((Date()-[WM DOH])/365,2) AS YearsOfService, tblAccrual.WeeksAccrual
FROM Roster, tblAccrual
WHERE (([tblAccrual]![Years]<[YearsOfService]))
GROUP BY Roster.UserID, Roster.[WM DOH], Round((Date()-[WM DOH])/365,2), tblAccrual.WeeksAccrual;
My query should return the number of accrual weeks based on years of service. When I run the query it asks in an input box for the YearsOfService. What I am looking for is to have the appropriate accrual value return for teh user based on their years of service. When I remove the “Where” piece it returns all combinations for the various years of service value. I only want the one corresponding to their years of service. In excel I have a formula like…
Today - Date of Hire / 365 = Years of service
if(years of service <2,0, if(years of service <7,2, if Years of service <15,3, 4)))
What have I done wrong?
You cannot refer to the alias
YearsOfServicein the Where statement, use something like:From the number of parentheses, it seems you are building using the query design window, it can help to put a criterion under the aliased column to see what MS Access suggests.