I have a query that returns the following dataset:
RELATIONid MAPid D1id D2id D3id
4999 4999 626 1250 7
5000 5000 626 1250 8
For the next step, I need to bind those datasets into treeview (hierarchy structure). I need to transform this dataset into the following:
Nodeid ParentNodeid Header
626 null D1
1250 626 D2
7 1250 D3
8 1250 D3
How I can achieve those structure from the original dataset?
I have one more favor to ask, the data structure a (little bit) more complex than the previous one. Let's say I have sample dataset like this:
RELATIONid MAPid D1id D2id D3id
4999 4999 626 1250 7
5000 5000 626 1250 8
5001 5001 627 1300 10
5002 5002 627 1300 12
5003 5003 628 1400 15
From the following dataset, we have 3 MainParent: 626, 627, 628
and the transformation (cross apply) output expectation will be like this:
Nodeid ParentNodeid Header
626 null D1
1250 626 D2
7 1250 D3
8 1250 D3
627 null D1
1300 627 D2
10 1300 D3
12 1300 D3
628 null D1
1400 628 D2
15 1400 D3
Please note that the data are ordered per ParentNode
followed by its node data.