i have the following code. my problem is i want to retrieve each employee name from another table name Employee which has a EmployeeID column similar to the AccessLog table, I used in this current query. now when i m joining these 2 table it is giving that weird error i said on the title. without the added code for joining- A.EmployeeID, Employee.FirstName in the first SELECT and ; AS A INNER JOIN Employee ON A.EmployeeID= Employee.EmployeeID to the last ORDER By clause, it is working good. I think problem is in the naming/alias. there are similar thread i saw, but those did not solve my problem. If someone could point me the fault, will appreciate.
SELECT **A.EmployeeID,
Employee.FirstName,**
MonthName(Month([LogDate])) AS MonthName,
Round((Sum(Int(DateDiff("s",'00:00:00',Duration)))/3600)) AS TotalTime
FROM (
SELECT AccessLog.EmployeeID,
AccessLog.LogDate,
AccessLog.TerminalID,
AccessLog.LogTime,
Format((SELECT max(LogTime)
FROM AccessLog AS Alias
WHERE Alias.LogTime < AccessLog.LogTime
AND Alias.EmployeeID = AccessLog.EmployeeID
AND Alias.LogDate = AccessLog.LogDate
AND (Alias.TerminalID)<>"iGuard1A"
And (Alias.TerminalID)<>"iGuard1B"
AND Alias.EmployeeID = AccessLog.EmployeeID),"hh:nn:ss") AS PrevTime,
Format((ElapsedTime(iif(PrevTime = '',logtime,prevtime),[LogTime])),"hh:nn:ss") AS Duration,
AccessLog.InOut
FROM AccessLog
WHERE (((AccessLog.TerminalID)<>"iGuard1A"
And (AccessLog.TerminalID)<>"iGuard1B")
AND ((AccessLog.EmployeeID) Like "2*")
AND ((AccessLog.InOut)="OUT"))
ORDER BY AccessLog.EmployeeID, AccessLog.LogDate, AccessLog.LogTime)
**AS A INNER JOIN Employee ON A.EmployeeID= Employee.EmployeeID**
GROUP BY EmployeeID, MonthName(Month([LogDate]));
i solved it. As i said there is name/alias issue. I had to give seperate alias to the same table used in every subquery. even after that it show another error of aggragate function for the firstname in the top select, i also solved that by including it in a subquery. so in full my code goes as follows: