is this u wantdeclare @str table( ParentID INT,ID int, Name varchar(32))insert into @str select NULL,10001,'Region1' union all selectNULL,10002,'Region2' union all selectNULL,10003,'Region3' union all select10001,501,'Test1' union all select10001,502,'Test2' union all select10002,503,'Test3' union all select10002,504,'Test4' union all select10003,505,'Test5' union all select10003,506,'Test6' union all select501,507,'Test7' union all select501,508,'Test8' union all select502,509,'Test9' union all select502,510,'Test10'--select * from @str;with cte(id,parentid,name,parentname)as(select id,parentid,name,name from @str where parentid is nullunion allselect t.id,t.parentid,t.name,c.name from @str t inner join cte c on c.id = t.parentid)select * from cte where parentid is not null order by 1