Access 2007 Windows7
I have done quite a few queries/SQL in the past but am rusty, having not done it for several years.
I have been trying to get the following query to work and have been getting nothing but Syntax errors and other errors.
Several posts lead me to believe that this is possible but at present I have had very limited success in Access.
First table
EmpWhoWorkedOnJobAR
EmpWhoWorkedOnJobAR.TimeRecordID
EmpWhoWorkedOnJobAR.JobID
EmpWhoWorkedOnJobAR.JobNumber
EmpWhoWorkedOnJobAR.JobName
EmpWhoWorkedOnJobAR.EmployeeName
EmpWhoWorkedOnJobAR.EmployeeID
EmpWhoWorkedOnJobAR.DateofWork
EmpWhoWorkedOnJobAR.HoursWorked
Second Table
EmployeeCost
EmployeeCost.IDEmpCost
EmployeeCost.EmployeeID
EmployeeCost.EmployeeLoadedCost
EmployeeCost.EffectiveDate
I need to match the record in the first table to the correct cost in table 2 based on Max EffectiveDate that is EmployeeCost.EffectiveDate<=EmpWhoWorkedOnJobAR.Da teofWork
The following query works to find a max EffectiveDate base on today
SELECT T1.EmployeeID, T1.EffectiveDate, T1.EmployeeLoadedCost
FROM EmployeeCost AS T1 INNER JOIN (SELECT EmployeeID, Max(EffectiveDate) AS CostDate FROM EmployeeCost WHERE EmployeeCost.EffectiveDate<=Date() GROUP BY EmployeeCost.EmployeeID) AS T2 ON (T1.EmployeeID=T2.EmployeeID) AND (T1.EffectiveDate=T2.CostDate);
But the nested join versions I have tried don't work.
Example of latest try
SELECT T.JobID, T.JobNumber, T.JobName, T.EmployeeName, T.EmployeeID, T.DateofWork, T.HoursWorked,
T1.EmployeeID, T1.EffectiveDate, T1.EmployeeLoadedCost
FROM EmpWhoWorkedOnJobAR As T LEFT JOIN (SELECT T1.EmployeeID, T1.EffectiveDate, T1.EmployeeLoadedCost
FROM EmployeeCost WHERE(T1.EmployeeID=(SELECT T2.EmployeeID FROM EmployeeCost as T2 WHERE ( Max(T2.EffectiveDate) <= T.DateofWork ) GROUP BY T2.EmployeeID) As T1) ON T1.EmployeeID=T2.EmployeeID;
Any help appreciated.