Cómo conseguir que todos los hijos de un padre y luego sus hijos utilicen la recursión en la consulta

Tengo una estructura como esta:

<Unit>
  <SubUnit1>
           <SubSubUnit1/>
           <SubSubUnit2/>
           ...
           <SubSubUnitN/>
  </SubUnit1/>
  <SubUnit2>
           <SubSubUnit1/>
           <SubSubUnit2/>
           ...
           <SubSubUnitN/>
  </SubUnit2/>
  ...
  <SubUnitN>
           <SubSubUnit1/>
           <SubSubUnit2/>
           ...
           <SubSubUnitN/>
  </SubUnitN/>
</Unit>

Esta estructura tiene 3 niveles: unidad principal, subunidades y subunidades.

Quiero seleccionar a todos los niños por UnitId.
Si busco por Unidad, tengo que conseguir todo el árbol.
Si busco por SubUnit1, tengo que obtener SubUnit1 y todos los hijos de SubUnit1.
Si busco SubSubUnit2, tengo que conseguirlo.

Aquí está mi intento:

with a(id, parentid, name)
as (
select id, parentId, name
   from customer a
   where parentId is null 
union all
   select a.id, a.parentid, a.Name
   from customer
     inner join a on customer.parentId = customer.id
    )
select parentid, id, name 
from customer pod
where pod.parentid in (
select id
from customer grbs
where grbs.parentid in (
select id
from customer t
where t.parentid = @UnitId
))
union 
select parentid, id, name
from customer grbs
where grbs.parentid in (
select id
from customer t
where t.parentid = @UnitId
)
union
select parentid, id, name
from customer c
where c.Id = @UnitId
order by parentid, id

Uso 3 palabras de unión, no está bien pero funciona. La estructura del caso tendrá N niveles, ¿cómo debo obtener el resultado correcto?

Respuestas a la pregunta(2)

Su respuesta a la pregunta