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.
Author |
Topic |
masteripper
Starting Member
25 Posts |
Posted - 2012-04-10 : 07:39:02
|
Hello to eveybody...i am struggling with a situation and i would like some adviceI have this kind of structure in my tableID.........ParentID.....Level01...........NULL..........001-02........01............101-03........01............101-02-01...01-02.......201-02-02...01-02.......201-03-01...01-03.......2What i need is "traverse" the tree in reverse order to produce the following resultLevel0....Level1.......Level201.........01-02.....01-02-0101.........01-03.....01-03-01I want to give the ids of highest Level and produce all the backwards hierarcyBy the Way ...don't limit it to 3 levels (for now i have 6) unless is the only wayThanks in advance |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
masteripper
Starting Member
25 Posts |
Posted - 2012-04-10 : 16:23:35
|
I have already CTE the table but i cannot "generate" the level columns...thats my problemI know ID.....ParentID...Levelxx.......Null......0xx-xx.....xx.......1xx-xx-xx..xx-xx...2the problem is the showing of the hierarchylevel0....level1....level2............levelNxx........xx-xx......xx-xx-xx......xx-xx-...xxx(n) |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-10 : 16:30:08
|
you just need to PIVOT based on level values------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
masteripper
Starting Member
25 Posts |
Posted - 2012-04-11 : 01:52:28
|
Well i have done ....i didn't want to change the compatibility Level of my DB but i checked it and it caused no problems so i moved onNow the question is how to eliminate the NULLSNow01....01-00..........01-00-01..........01-00-02I want01....01-00....01-00-0101....01-00....01-00-02 |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-12 : 01:05:51
|
apply group by and max() over columns------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|