Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Best option for recursive parent child loop

$
0
0

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 


Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>