with area as(
select Orderid,FatherOrderid,rtrim(PartName) as NodeText,left('00',2-len(row_number() over (order by partindex)))+ CONVERT(varchar,row_number() over (order by partindex)) as d,0 as liu,op as 这列不用 from #Temp_Tree where FatherOrderid = 419197
union all
select a.Orderid,a.FatherOrderid,rtrim(a.PartName) as NodeText,left('00',2-len(row_number() over (order by a.partindex)))+ CONVERT(varchar,row_number() over (order by a.partindex)) as d,0 as liu,a.op as 这列不用 from #Temp_Tree a join area b on a.FatherOrderid=b.Orderid
where a.PartType = 2--Orderid in (select FatherOrderid from #Temp_Tree )
)select * from area