December 19, 2008 at 5:21 am
I don't mean to offend anyone but...
Why does everyone insist on putting this check in the WHERE clause? It's messy and a Where clause usually complains when you try and come back with multiple values (or multiple columns) in the sub-Select.
Do a regular inner join. It's simpler and probably more quick. BTW, since an alias isn't used on the outer "UserName" column, I guessed which table it came from. Change it if it's wrong.
Select bg.BusinessGroup, pme.EmployeeName, pme.ReportingTo, pme.Location,
t1.LogDate as LastLoginDate
From tbl_pm_employee pme
Inner join tbl_CNF_BusinessGroups bg
on bg.BusinessGroupID=pme.BusinessGroupID
Inner Join tbl_PM_location pml
on pml.locationid=mpe.locationid
Inner Join (Select UserName, max(Logdate) As LogDate
from tbl_PBN_debugging
group by UserName
Having DATEDIFF(dd, MAX(Logdate), GETDATE()) >= 90) t1
on pme.UserName = t1.UserName
December 19, 2008 at 5:27 am
Actually, it occurs to me to wonder if you have a link in some other table from UserID to UserName?
If UserName is not in any of the three tables you're joining to originally, but UserID is, and there's another table that associates UserID to UserName, you'll need to add that table to your query so you can properly reach the logging table.
Viewing 2 posts - 16 through 16 (of 16 total)
You must be logged in to reply to this topic. Login to reply