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
 General SQL Server Forums
 New to SQL Server Programming
 CTE to Select Fewer Childrens

Author  Topic 

afzaal820
Starting Member

19 Posts

Posted - 2011-06-17 : 04:20:58
Name ID
CEO 0
+Director 1
++ Manager 1
+++ Employee 1
+++ Employee 2
++ Manager 2
+++ Employee 3
+++ Employee 4
+ Director 2
++ Manager 3
+++ Employee 5
+++ Employee 6
++ Manager 4
+++ Employee 7
+++ Employee 8

Consider this Hierachy now i need to select the hierarachy of Employee 6, 4, 2.

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-06-17 : 07:06:58
How is the table structured?
i.e. how do you know that employee 5 has manager 3 and director 2
(and don't say it's because of the order as the table has no order)

I suspect you have a parent id of some sort in the table or could be some other method.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-06-17 : 07:07:08
1. How is Employee 6 related to Manager 4? From your sample data, Manager 3 is the manager of Employee 6.

2. What is your input to the query?
Go to Top of Page
   

- Advertisement -