heirarchial data from self referencing table in tree form
- by Beta033
Ii looks like this has been asked and answered in all the simple cases, excluding the one that i'm having trouble with. I've tried using a recursive CTE to generate this, however maybe a cursor would be better? or maybe a set of recursive functions will do the trick?
Can this be done in a cte?
consider the following table
PrimaryKey ParentKey
1 NULL
2 1
3 6
4 7
5 2
6 1
7 NULL
should yield
PK
1
-2
--5
-6
--3
7
-4
where the number of - marks equal the depth, my primary difficulty is the ordering.