I have the following hierarchical table:
Table Category: CategoryId, ParentCategoryId, CategoryName 1, null, SomeRoot 2, 1, SomeChild 3, 2, SomeGrandchild 4, 3, SomeGreatGrandchild
(note that in this example, the data does not include a sheet on an earlier node than level 4, but this is possible). This data will never be deeper than level 4, if that matters. I would like to convert / rotate to this fixed 4-level display
CatId, Name1, Name2, Name3, Name4 1, SomeRoot, null, null, null 2, SomeRoot, SomeChild, null, null 3, SomeRoot, SomeChild, SomeGrandchild, null 4, SomeRoot, SomeChild, SomeGrandchild, SomeGreatGrandchild
I made a left outer join to the category table 4 times and built a huge case statement to determine the level that will be used for the ID field, but which does not include zero lines .... Any ideas? HELP!