help for recursive query | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

help for recursive query

I have a table that represents a tree structure via a self-join. e.g. given id parentid
1 NULL
2 1
3 2
4 2
5 1
6 4
7 NULL
8 7
9 7
10 9
11 10 I need to get the root of the given child.
for example: if the given child is 6 then return 1. if child=10 then return 7. I need this in a single query only, is it possible?
http://msdn2.microsoft.com/en-us/library/ms186243.aspx Madhivanan Failing to plan is Planning to fail
quote:Originally posted by Madhivanan http://msdn2.microsoft.com/en-us/library/ms186243.aspx Madhivanan Failing to plan is Planning to fail

The recursive example given inhttp://msdn2.microsoft.com/en-us/library/ms186243.aspx only for the whole structure of the tree result. It can’t produce what i expected also. thanks Madhivanan
]]>