はここCTEアプローチの例です:
declare @t table (id int, type varchar(10), name varchar(50), parentid int)
insert @t
select 1, 'COUNTRY', 'AU', null
union all select 2, 'STATE', 'Guiness State', 1
union all select 3, 'STATE', 'Pilsner State', 1
union all select 4, 'REGION', 'Heineken Region', 2
union all select 5, 'REGION', 'Bud Light Region', 3
union all select 6, 'TOWN', 'Hoegaarden Town', 2
union all select 7, 'TOWN', 'Corona Town', 2
union all select 8, 'TOWN', 'Leffe Town', 3
; with recursed as
(
select *
from @t as root
where root.name = 'Guiness State'
union all
select child.*
from recursed as parent
join @t as child
on parent.id = child.parentid
)
select *
from recursed
Code sample at SE Data.