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)
 Parent Child Query

Author  Topic 

jubinjose
Starting Member

20 Posts

Posted - 2008-03-17 : 03:50:14
My table structure is - employee_id employee_name manager_id

manager_id will point to another record in the same table because ultimately manager is also an employee. CEO doesn't report to anyone and hence his manager_id is null

Sample data
employee_id, employee_name, manager_id,
1 John 3
3 Jim 2
2 Tom 5
5 Alex null

Now I want to be able to accept an employee_id as parameter and output his reporting hierarchy. So if my input parameter is 1, my output should be
Alex\Tom\Jim\John

What is an elegant query to get this result?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-03-17 : 05:40:01
Read about Expanding Hierarchies in sql server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -