select ParentPart,Component into #t1 from BomStructure where ParentPart ='X' and Route ='0'
select b.ParentPart,b.Component into #t2 from BomStructure b join #t1 on #t1.Component = b.ParentPart where Route ='0'
select b2.ParentPart,b2.Component into #t3 from BomStructure b2 join #t2 on #t2.Component = b2.ParentPart where Route ='0'
select * from #t1
union
select * from #t2
union
select * from #t3
drop table #t1
drop table #t2
drop table #t3
|