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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-05-23 : 09:01:12
|
Madhukar Hebbar writes "Hi , I have a table schema like this.. EmployeeId Name managerId 1 ABC <NULL> 2 XYZ 1 3 PQR 1 4 MNO 3 5 STU 4 Here managerId and EmployeeId are related.Can I have a query for this table so that if I give a manager name then I have to get all the employees under him (Like a organisation tree). for Eg.:- If a give ABC then I have to get alll the records in the table shown above. Thanks Madhukar Hebbar M" |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-05-23 : 09:03:23
|
| Take a look at this article:http://www.sqlteam.com/item.asp?ItemID=8866If you have a setup like that, you can find all of a manager's subordinates with the following:SELECT * FROM EmployeesWHERE Lineage Like '%/' + CAST (@managerID as varchar) + '/%' |
 |
|
|
|
|
|