Этот код объединяет строку и отображает только последний родительский элемент
declare @casetypes table(code nvarchar(max), title varchar(20), parent int, id int)
insert @casetypes values ('a', 't1', null, 1)
insert @casetypes values ('b', 't2', 1, 2)
insert @casetypes values ('c', 't3', 2, 3)
;WITH
hi as (
select c.id id, cast(c.code as nvarchar) code, c.title, c.parent
from @CaseTypes c
where c.parent is null
union all
select c.id, cast((h.code + c.code ) as nvarchar) code , c.title, c.parent from @CaseTypes c
inner join hi h on c.parent = h.id
)
select id, code, parent
from hi h
where not exists (select 1 from hi where h.id = parent )