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
 Hierarchy all the childs

Author  Topic 

amodi
Yak Posting Veteran

83 Posts

Posted - 2009-09-14 : 07:58:14
Hello Friends,

I have a table that maintains heirarchy. When input is passed( can be one or more parentId in a table), all of its childId(and child's childIds...) should be the output

childId-------parentId
46------------18
5-------------46
6-------------5
7-------------6
8-------------6
9-------------6
10------------6
11------------6
12------------6
13------------6
14------------6

For example: when the input is 18.

The output should be:
46
5
6
7
8
9
10
11
12
13
14

Thanks a million.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-09-14 : 08:06:17
if you are using SQL 2005 / 2008, you can use recursive CTE

here is the link to that in BOL
http://msdn.microsoft.com/en-us/library/ms186243.aspx


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -