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)
 Flatten a hirearchy

Author  Topic 

bis188
Starting Member

3 Posts

Posted - 2005-02-11 : 01:45:49
I need some help to flattern a hirearchy. Say I have something like

N
|
1
/ 2 3
/4 5
/
6

My source table is
Node, Parent
1 null
2, 1
3, 1
4, 2
5, 2
6, 5

I want to output a table like this with 4 columns

lev1, levl2, levl3, level4
===== ====== ====== ======
1 null null null
1 2 null null
1 3 null null
1 2 4 null
1 2 5 null
1 2 5 6


Of course this is a cut down version of the real problem.
I have 35 thousand rows of data like this to deal with, the
good news is I know there is a maxium of 15 levels. I am not sure
how to work this, at any given row in my source table, I have
only a parent and child info and I don't know which level it belongs.
There must be an algorithum out there expand this.

Can you help please and thank you !

bis188
Starting Member

3 Posts

Posted - 2005-02-11 : 01:52:10
I just notice the post scramble up my "graph"
but I think you all know what I meant. It's 4 level with
1 on top, 2 & 3 on the 2nd level , 4 & 5 on the 3rd and 6 the fourth level. I want to flattern out with 6 records and each record has 4 columns (because that's how deep the graph is).

Thank you again !
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-02-11 : 01:59:57
Check this http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=43485

Madhivanan
Go to Top of Page
   

- Advertisement -