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 |
|
srinuganaparthi
Starting Member
1 Post |
Posted - 2011-08-04 : 01:45:33
|
| hi i Need to get all Employyes working under Managersi have table structure like thisEmpId EmpName Email ManagerId1 James James@gmail.com Null2 Kenny kenny@gmail.com 13 Anderson Andes@gmail.com 24 Jasmin Jasmin@gmail.com 3Here if i give EmpId as 1 i need to get all employees who are working under Employee Jamessuppose Kenny is working under James and Anderson is working under KennyMeans Anderson is indirectly working under Jamesthis way i need to get all the recordsif i give EmpId as 1 i need to Kenny,Anderson and Jasmin Recordsif i give EmpId as 2 i need to Anderson and Jasmin Recordsif i give EmpId as 3 i need to get only Jasmin RecordI have writtend query but its giving only immediate Manager .here is the query what i have writtenSELECT e.EmpId,e.EmpName AS 'Employee Name',e.Email, m.EmpName AS 'Manager Name',m.EmpIdFROM Employee AS e JOIN Employee AS mON e.ManagerID =m.EmpId and e.EmpId=1Please help me out,its very urgentRegardsSrinivas Ganaparthi. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-08-04 : 02:35:38
|
you will need to use Recursive CTE KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
tkatende
Starting Member
8 Posts |
Posted - 2011-08-04 : 16:53:47
|
| try using a self join |
 |
|
|
|
|
|