批量子件反查,查成品
create table #temp2
(
wlbh varchar(20),
cpbh varchar(20)
)
declare @ph varchar(20)
declare @count int
declare @i int
select @count=count() from dz$
set @i=1
while(@i<=@count)
begin
;with
dcbom as
(select prd_no,bom_no from tf_bom where prd_no in (select ph from dz$ where xh=@i )
union all
select dcbom.prd_no,tf_bom.bom_no from tf_bom,dcbom where tf_bom.prd_no+’->’=dcbom.bom_no
)
insert into #temp2 select dcbom. from dcbom where left(bom_no,1)=‘3’
set @i=@i+1
end
select * from #temp2