We have a table like this (simplified version):
Items:
Itemid Itemname Itemfatherid
itemA theitemA null
itemB theitemB null
itemC theitemC itemA
itemD theitemD itemA
itemE theitemE itemC
itemF theitemF itemE
itemG theitemG itemD
We need a sql query that gives the following result/format: (Corrected version)
Col1 Col2 Col3 Col4
itemA itemC itemE itemF
itemA itemD itemG NULL
itemB NULL NULL NULL
Our ERP would take this resul and convert it to a tree control like this:
-itemA
-itemC
-itemE
itemF
-itemD
itemG
itemB
The level of the tree is not fixed so the number of columns must be dynamic...
There is some way with CTEs but we can't reach te solution yet :S
http://www.sqlservercurry.com/2009/06/simple-family-tree-query-using.html
Also we need to know the depth of the tree (to pass it to the GridControl...) in this example it would be 3 (it takes the max number of parent levels --> -itemA -itemC -itemE)