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
 Transact-SQL (2000)
 Employee manager relation

Author  Topic 

madhukar
Starting Member

3 Posts

Posted - 2002-05-21 : 04:59:49
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 I give 'ABC' as manager then I have to get alll the records in the table shown above.

Thanks
Madhukar Hebbar M


karthikms
Starting Member

1 Post

Posted - 2002-05-21 : 06:02:10
Try this.

select lpad(' ',2*(level-1)) || name name from <table name>
start with name = '<manager name>'
connect by prior employeeid = managerid;

Regards,

Karthik.

Go to Top of Page

madhukar
Starting Member

3 Posts

Posted - 2002-05-21 : 07:24:19
Doesn't work with sql server. Anything else in SQl Server..


Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-05-21 : 07:42:53
Take a look at this:

http://www.sqlteam.com/item.asp?ItemID=8866

If you need a full tree, that's one option to use in order to get it.

Go to Top of Page
   

- Advertisement -