Showing posts with label root. Show all posts
Showing posts with label root. Show all posts

Monday, March 12, 2012

Query to get the names of items with different levels

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

Now I want to show this data as

Root -> Trunk -> Branch -> Leaf

How to write the query for getting the Names for different levels for corresponding ParentID...select case when level is 1 then Name end as Root,
case when level is 2 then Name end as Trunk,
case when level is 3 then Name end as Branch,
case when level is 4 then Name end as Leaf,
case when level is 5 then Name end as Stem

Quote:

Originally Posted by sree078

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

Now I want to show this data as

Root -> Trunk -> Branch -> Leaf

How to write the query for getting the Names for different levels for corresponding ParentID...