create table ##createbom2(bomtypeno varchar(30), one varchar(30),two varchar(30),three varchar(30),four varchar(30),five varchar(30),isqz varchar(15),isjg varchar(15),zxqty int,gdxdsl int,qzxdsl varchar(20),wc int)
if exists(select 1 from pd_autocreatebom where sprccode =@astr )
begin
insert ##createbom2(bomtypeno,one ,two ,three ,four ,five,isqz ,isjg ,zxqty ,gdxdsl ,qzxdsl ,wc )
select c.orderno,b.one,b.two,b.three,b.four,b.five,b.isqz,b.isjg,b.zxqty,b.gdxdsl,b.qzxdsl,b.wc from pd_autocreatebom a with(nolock)
inner join pd_pd_autocreatebomlist b with(nolock) on a.billno=b.billno
inner join sa_baojiatype c with(nolock) on a.sprccode=c.typeno
where @astr=A.sprccode
declare createbom2 cursor for
select * from ##createbom2
open createbom2
fetch next from createbom2 into @bomtypeno,@one ,@two ,@three ,@four ,@five,@isqz ,@isjg ,@zxqty ,@gdxdsl ,@qzxdsl ,@wc
while @@fetch_status=0
begin
select @one ,@two ,@three ,@four ,@five,@isqz ,@isjg ,@zxqty ,@gdxdsl ,@qzxdsl ,@wc --test
--业务id:99215
--规格型号部分
if @isqz<>''
set @onebomup=@isqz+'-'+@one
else
set @onebomup=@one
select @onebomup --test
-----第二级的bom
if @two<>''
begin
--第二级的bom
if @two not like 'number'+'%'
begin
if @i=2
begin
select @twobomup=
case when @secondpart like @two+'%' then @secondpart
end
end
if @i=3
begin
select @twobomup=
case when @secondnum_up like @two+'%' then @secondnum_up
when @thirdpart like @two+'%' then @thirdpart
end
end
if @i=4
begin
if @firstpart<>'ECX02'
BEGIN
select @twobomup=
case when @secondnum_up like @two+'%' then @secondnum_up
when @thirdpart_s like @two+'%' then @thirdpart_s
when @fourpart1 like @two+'%' then @fourpart1
end
END
if @firstpart='ECX02'
BEGIN
SET @twobomup=@secondnum_up
END
end
if @i=5
begin
select @twobomup=
case when @secondnum_up like @two+'%' then @secondnum_up
when @thirdpart_s like @two+'%' then @thirdpart_s
when @fourpart1_up like @two+'%' then @fourpart1_up
when @fivepart1 like @two+'%' then @fivepart1
end
end
if @i=6
begin
select @twobomup=
case when @secondnum_up like @two+'%' then @secondnum_up
when @thirdpart_s like @two+'%' then @thirdpart_s
when @fourpart1_up like @two+'%' then @fourpart1_up
when @fivepart1_up like @two+'%' then @fivepart1_up
when @sixpart1 like @two+'%' then @sixpart1
end
end
if @i=7
begin
select @twobomup=
case when @secondnum_up like @two+'%' then @secondnum_up
when @thirdpart_s like @two+'%' then @thirdpart_s
when @fourpart1_up like @two+'%' then @fourpart1_up
when @fivepart1_up like @two+'%' then @fivepart1_up
when @sixpart1_up like @two+'%' then @sixpart1_up
when @sevenpart1 like @two+'%' then @sevenpart1
end
end
if @i=8
begin
select @twobomup=
case when @secondnum_up like @two+'%' then @secondnum_up
when @thirdpart_s like @two+'%' then @thirdpart_s
when @fourpart1_up like @two+'%' then @fourpart1_up
when @fivepart1_up like @two+'%' then @fivepart1_up
when @sixpart1_up like @two+'%' then @sixpart1_up
when @sevenpart1_up like @two+'%' then @sevenpart1_up
when @eightpart1 like @two+'%' then @eightpart1
end
end
if @i=9
begin
select @twobomup=
case when @secondnum_up like @two+'%' then @secondnum_up
when @thirdpart_s like @two+'%' then @thirdpart_s
when @fourpart1_up like @two+'%' then @fourpart1_up
when @fivepart1_up like @two+'%' then @fivepart1_up
when @sixpart1_up like @two+'%' then @sixpart1_up
when @sevenpart1_up like @two+'%' then @sevenpart1_up
when @eightpart1_up like @two+'%' then @eightpart1_up
when @ninepart1 like @two+'%' then @ninepart1
end
end
if @i=10
begin
select @twobomup=
case when @secondnum_up like @two+'%' then @secondnum_up
when @thirdpart_s like @two+'%' then @thirdpart_s
when @fourpart1_up like @two+'%' then @fourpart1_up
when @fivepart1_up like @two+'%' then @fivepart1_up
when @sixpart1_up like @two+'%' then @sixpart1_up
when @sevenpart1_up like @two+'%' then @sevenpart1_up
when @eightpart1_up like @two+'%' then @eightpart1_up
when @ninepart1_up like @two+'%' then @ninepart1_up
when @tenpart1 like @two+'%' then @tenpart1
end
end
if @i=11
begin
select @twobomup=
case when @secondnum_up like @two+'%' then @secondnum_up
when @thirdpart_s like @two+'%' then @thirdpart_s
when @fourpart1_up like @two+'%' then @fourpart1_up
when @fivepart1_up like @two+'%' then @fivepart1_up
when @sixpart1_up like @two+'%' then @sixpart1_up
when @sevenpart1_up like @two+'%' then @sevenpart1_up
when @eightpart1_up like @two+'%' then @eightpart1_up
when @ninepart1_up like @two+'%' then @ninepart1_up
when @tenpart1_up like @two+'%' then @tenpart1_up
when @elvpart1 like @two+'%' then @elvpart1
end
end
if @i=12
begin
select @twobomup=
case when @secondnum_up like @two+'%' then @secondnum_up
when @thirdpart_s like @two+'%' then @thirdpart_s
when @fourpart1_up like @two+'%' then @fourpart1_up
when @fivepart1_up like @two+'%' then @fivepart1_up
when @sixpart1_up like @two+'%' then @sixpart1_up
when @sevenpart1_up like @two+'%' then @sevenpart1_up
when @eightpart1_up like @two+'%' then @eightpart1_up
when @ninepart1_up like @two+'%' then @ninepart1_up
when @tenpart1_up like @two+'%' then @tenpart1_up
when @elvpart1_up like @two+'%' then @elvpart1_up
when @tlepart1 like @two+'%' then @tlepart1
end
end
select @twobomup --test
--业务id:99215
-----第三级的bom
if @three<>''
begin
if @three not like 'number'+'%'
begin
if @i=3
begin
select @threebomup=
case when @secondnum_up like @three+'%' then @secondnum_up
when @thirdpart like @three+'%' then @thirdpart
end
end
if @i=4
begin
select @threebomup=
case when @secondnum_up like @three+'%' then @secondnum_up
when @thirdpart_s like @three+'%' then @thirdpart_s
when @fourpart1 like @three+'%' then @fourpart1
end
end
if @i=5
begin
select @threebomup=
case when @secondnum_up like @three+'%' then @secondnum_up
when @thirdpart_s like @three+'%' then @thirdpart_s
when @fourpart1_up like @three+'%' then @fourpart1_up
when @fivepart1 like @three+'%' then @fivepart1
end
end
if @i=6
begin
select @threebomup=
case when @secondnum_up like @three+'%' then @secondnum_up
when @thirdpart_s like @three+'%' then @thirdpart_s
when @fourpart1_up like @three+'%' then @fourpart1_up
when @fivepart1_up like @three+'%' then @fivepart1_up
when @sixpart1 like @three+'%' then @sixpart1
end
end
if @i=7
begin
select @threebomup=
case when @secondnum_up like @three+'%' then @secondnum_up
when @thirdpart_s like @three+'%' then @thirdpart_s
when @fourpart1_up like @three+'%' then @fourpart1_up
when @fivepart1_up like @three+'%' then @fivepart1_up
when @sixpart1_up like @three+'%' then @sixpart1_up
when @sevenpart1 like @three+'%' then @sevenpart1
end
end
if @i=8
begin
select @threebomup=
case when @secondnum_up like @three+'%' then @secondnum_up
when @thirdpart_s like @three+'%' then @thirdpart_s
when @fourpart1_up like @three+'%' then @fourpart1_up
when @fivepart1_up like @three+'%' then @fivepart1_up
when @sixpart1_up like @three+'%' then @sixpart1_up
when @sevenpart1_up like @three+'%' then @sevenpart1_up
when @eightpart1 like @three+'%' then @eightpart1
end
end
if @i=9
begin
select @threebomup=
case when @secondnum_up like @three+'%' then @secondnum_up
when @thirdpart_s like @three+'%' then @thirdpart_s
when @fourpart1_up like @three+'%' then @fourpart1_up
when @fivepart1_up like @three+'%' then @fivepart1_up
when @sixpart1_up like @three+'%' then @sixpart1_up
when @sevenpart1_up like @three+'%' then @sevenpart1_up
when @eightpart1_up like @three+'%' then @eightpart1_up
when @ninepart1 like @three+'%' then @ninepart1
end
end
if @i=10
begin
select @threebomup=
case when @secondnum_up like @three+'%' then @secondnum_up
when @thirdpart_s like @three+'%' then @thirdpart_s
when @fourpart1_up like @three+'%' then @fourpart1_up
when @fivepart1_up like @three+'%' then @fivepart1_up
when @sixpart1_up like @three+'%' then @sixpart1_up
when @sevenpart1_up like @three+'%' then @sevenpart1_up
when @eightpart1_up like @three+'%' then @eightpart1_up
when @ninepart1_up like @three+'%' then @ninepart1_up
when @tenpart1 like @three+'%' then @tenpart1
end
end
if @i=11
begin
select @threebomup=
case when @secondnum_up like @three+'%' then @secondnum_up
when @thirdpart_s like @three+'%' then @thirdpart_s
when @fourpart1_up like @three+'%' then @fourpart1_up
when @fivepart1_up like @three+'%' then @fivepart1_up
when @sixpart1_up like @three+'%' then @sixpart1_up
when @sevenpart1_up like @three+'%' then @sevenpart1_up
when @eightpart1_up like @three+'%' then @eightpart1_up
when @ninepart1_up like @three+'%' then @ninepart1_up
when @tenpart1_up like @three+'%' then @tenpart1_up
when @elvpart1 like @three+'%' then @elvpart1
end
end
if @i=12
begin
select @threebomup=
case when @secondnum_up like @three+'%' then @secondnum_up
when @thirdpart_s like @three+'%' then @thirdpart_s
when @fourpart1_up like @three+'%' then @fourpart1_up
when @fivepart1_up like @three+'%' then @fivepart1_up
when @sixpart1_up like @three+'%' then @sixpart1_up
when @sevenpart1_up like @three+'%' then @sevenpart1_up
when @eightpart1_up like @three+'%' then @eightpart1_up
when @ninepart1_up like @three+'%' then @ninepart1_up
when @tenpart1_up like @three+'%' then @tenpart1_up
when @elvpart1_up like @three+'%' then @elvpart1_up
when @tlepart1 like @three+'%' then @tlepart1
end
end
实现自动建表的功能2
最新推荐文章于 2023-01-17 11:54:45 发布