Hello,
I have a continuous subform listing each employee which is based on a SQL statement, which changes depending upon the toggle switch located in the subform header. I have this working OK.
I now wish to add another field to the subform which will be based on a joined table. I am struggling to get the syntax correct for this subquery.
TblEmployee:
employeeID
employeeDept
employeeStatus
TblMovement:
movementID
employeeID (foreign key from TblEmployee)
movementDate
What would the correct syntax be for a subquery which finds the most recent movementDate in Tblmovement?
I have tried the following but it does not work:
Where the entire SQL statement would become:
I have a continuous subform listing each employee which is based on a SQL statement, which changes depending upon the toggle switch located in the subform header. I have this working OK.
I now wish to add another field to the subform which will be based on a joined table. I am struggling to get the syntax correct for this subquery.
TblEmployee:
employeeID
employeeDept
employeeStatus
TblMovement:
movementID
employeeID (foreign key from TblEmployee)
movementDate
What would the correct syntax be for a subquery which finds the most recent movementDate in Tblmovement?
I have tried the following but it does not work:
Code:
(SELECT TOP 1 Temp.movementDate FROM TblMovement INNER JOIN TblEmployee ON TblMovement.[employeeID]
=TblEmployee.[employeeID] As Temp WHERE Temp.[employeeID] = TblMovement.[employeeID]
And Temp.[movementDate] <= Date() ORDER BY Temp.movementDate DESC,
Temp.movementID) AS LastMove
Where the entire SQL statement would become:
Code:
SELECT TblEmployee.[employeeID], TblEmployee.[employeeDept], TblEmployee.[employeeStatus],
(SELECT TOP 1 Temp.movementDate FROM TblMovement INNER JOIN TblEmployee ON TblMovement.[employeeID]
=TblEmployee.[employeeID] As Temp WHERE Temp.[employeeID] = TblMovement.[employeeID]
And Temp.[movementDate] <= Date() ORDER BY Temp.[movementDate] DESC, Temp.[movementID]) AS LastMove
FROM TblEmployee, TblMovement WHERE (((TblEmployee.[employeeStatus])=1;