You would also need some logic to identify which branch you want to stop. Something like this:WITH cte AS
(
-- anchor query here
UNION ALL
-- recursive query starts here
FROM
YourTable y
INNER JOIN cte c ON c.Id = y.ParentId
WHERE -- stop recursion at level 11 for branchid = 32
c.Level < 11 OR y.BranchId <> 32
)
-- rest of the query here.