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.
Author |
Topic |
asifbhura
Posting Yak Master
165 Posts |
Posted - 2014-03-16 : 08:18:15
|
I have following table with data CREATE TABLE EMPLOYEE ( EmployeeId int, ManagerId int, EmployeeName varchar(10) ) INSERT EMPLOYEE SELECT 1,2,'Peter' INSERT EMPLOYEE SELECT 2,3,'David' INSERT EMPLOYEE SELECT 3,NULL,'Jane' INSERT EMPLOYEE SELECT 4,2,'Mary' INSERT EMPLOYEE SELECT 5,2,'Henry' I want output like below,Employee Manager Peter David David Jane Mary David Henry David andEmployee Manager Peter David David Jane Jane No Manager Mary David Henry David please help me out |
|
nagino
Yak Posting Veteran
75 Posts |
Posted - 2014-03-16 : 20:20:00
|
[code]SELECT E.EmployeeName Employee, M.EmployeeName ManagerFROM EMPLOYEE EINNER JOIN EMPLOYEE M ON E.ManagerId = M.EmployeeIDSELECT E.EmployeeName Employee, ISNULL(M.EmployeeName, 'No Manager') ManagerFROM EMPLOYEE ELEFT JOIN EMPLOYEE M ON E.ManagerId = M.EmployeeID[/code]-------------------------------------From JapanSorry, my English ability is limited. |
|
|
|
|
|
|
|