hi
I've a table with coln names
ID
Name
ParentID
Level
I've list with different levels
say
ex.
the Data is:-
ID Name ParentID Level
1 Root null 1
2 Trunk 1 2
3 Branch 2 3
4 Leaf 3 4
5 Stem 3 4
How to write the query for getting the Names for different levels for corresponding ParentID....
Output should be like:-
Leaf Branch Trunk Root
Stem Branch Trunk Root
I think you may want to check out hierarchical queries in Books Online. Here is a link with a good example I think you can adjust. http://vyaskn.tripod.com/hierarchies_in_sql_server_databases.htm
No comments:
Post a Comment