SQL Server to show a data tree in a specific format
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...