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 2000 Forums
 SQL Server Development (2000)
 Employee Manager relation

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=8866

If you have a setup like that, you can find all of a manager's subordinates with the following:

SELECT * FROM Employees
WHERE Lineage Like '%/' + CAST (@managerID as varchar) + '/%'


Go to Top of Page
   

- Advertisement -