I have some hierarchical data in a table. Linked via Parent Id's
eg.
i.e.
Some of the pages of my website can contain one or more of these items. (Managed by a cms)
The problem I have is that in each section, the ordering begins at 1. If I add an item to a page, and its position is susequently swapped (i.e. the display order for items 3 and 4 are swapped) then I can cope with that.
But, if I have items 3,4,6,7 on my page, and the order of their parents is swapped, I want to display 6,7,3,4.
so, how / what do I need to do so that I can query my hierarchy of data, and order them such that they will always be ordered in the right way, i.e. initially 1,2,3,4,5,6,7 but if the tier nodes are swapped, 1,5,6,7,2,3,4
All the select / order / group bys dont do what I want.
I have tried using the ROW_NUMBER() OVER function, but that doesnt quite seem to do what I need.
any ideas / comments / suggestions ?
eg.
Code:
pKey, Name, DisplayOrder, parentId
i.e.
Code:
1, 'Top Level',0,0
2, 'Tier Level',1,1
3, 'Sub Item 1',1,2
4, 'Sub Item 2',2,2
5, 'Tier Level',2,1
6, 'Sub Item 3',1,5
7, 'Sub Item 4',2,5
Some of the pages of my website can contain one or more of these items. (Managed by a cms)
The problem I have is that in each section, the ordering begins at 1. If I add an item to a page, and its position is susequently swapped (i.e. the display order for items 3 and 4 are swapped) then I can cope with that.
But, if I have items 3,4,6,7 on my page, and the order of their parents is swapped, I want to display 6,7,3,4.
so, how / what do I need to do so that I can query my hierarchy of data, and order them such that they will always be ordered in the right way, i.e. initially 1,2,3,4,5,6,7 but if the tier nodes are swapped, 1,5,6,7,2,3,4
All the select / order / group bys dont do what I want.
I have tried using the ROW_NUMBER() OVER function, but that doesnt quite seem to do what I need.
any ideas / comments / suggestions ?