I have data stored in a table with a parent child relationship. What I need to do is roll up from the furthest down all the way up. This could be quite a few levels. I have done this in c# with a recursive method call. SQL does not seem to be able to handle this as well as I thought with a CTE table. Maybe I am going about this all wrong but Your Ideas would be helpful. Below is a representation of what I am looking to do.
Index Parent
1 0
2 1
3 2
I want to be able to query it so I know that 3 belongs to 1 not just 2. Any suggestions?
Thanks
Matt