Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query Problem

Author  Topic 

ann
Posting Yak Master

220 Posts

Posted - 2010-08-25 : 15:10:17
Need to get the Manager & Report manager name from a users lookup table:

Table Project:
ProjectID, ProjName, Manager, ReportingManager
1, ProjectA, 1, 2
2, ProjectB, 3, null

Table Users:
UserID, FirstName, LastName
1, Joe, Smith
2, Mickey, Mouse
3, Daffy, Duck

Results:
ProjectA, Joe Smith, Mickey Mouse
ProjectB, Daffy Duck, NULL

I can get the project Manager name ok using an innerjoin, but I can't seem to figure out how to get the ReportingManager.

Can anyone help or point me in the right direction?

Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-08-25 : 15:55:03
Use LEFT JOIN instead of INNER JOIN to get your data.

SELECT *
FROM Project AS p
LEFT JOIN Users AS m ON m.UserID = p.Manager
LEFT JOIN Users AS rm ON rm.UserID = p.ReportingManager



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -