Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

GET all children for parents

$
0
0

Hi all - i have this code to get all the children under a particular parent and it is working but it only works with one parent at a time. how can i modify this so that I can pass multiple parents and get their children as well those parents? Thanks for helping out.

with [CTE] as (
    select * from [TheTable] c where c.[ParentId] = 1
    union all
    select * from [CTE] p, [TheTable] c where c.[ParentId] = p.[NodeId]
)
select * from [CTE]



Viewing all articles
Browse latest Browse all 23857

Trending Articles



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