博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数据匹配关联
阅读量:7045 次
发布时间:2019-06-28

本文共 1556 字,大约阅读时间需要 5 分钟。

hot3.png

--創建一個臨時表,用來保存對應的手冊號

create table #tempt3(PZHao int,[count] numeric(15,5),manualNo varchar(20))

--保存到臨時表中

insert into #tempt3 

select b.PZHao,b.count,c.manualNo  from Finished a left join #tempt2  b on a.PZHao=b.PZHao 

inner join  BaseInfo c on a.baseInfoId=c.baseInfoId

where b.PZHao is not null and 

a.baseInfoId in(select top 1 baseInfoId from BaseInfo where contractStatus='1' order by baseInfoId)

--select * from #tempt3

--獲取第二個憑證號對應的手冊號

--這個地方可以循環插入的

declare @rount int ,@jilu int,  int

set @rount=0

set @jilu=1

set @num=0

select @rount=count(*) from BaseInfo where contractStatus ='1' 

while @jilu<@rount

begin

print @jilu

insert into #tempt3

select distinct  b.PZHao,b.count,c.manualNo from Finished  a left join #tempt2 b on a.PZHao=b.PZHao

inner join BaseInfo c on a.baseInfoId=c.baseInfoId

where b.PZHao is not null and 

c.manualNo in(select top 1 manualNo from BaseInfo where contractStatus ='1' and 

  manualNo not in(select manualNo from #tempt3) order by  baseInfoId   )

and b.PZHao not in(select PZHao from #tempt3 )

order by b.PZHao

set @jilu=@jilu+1

end

--select * from #tempt3 

select @num=count(manualno) from  Repertoy_package_materials_sum where manualno in (select manualno from #tempt3)

if @num>0

 begin

delete from Repertoy_package_materials_sum where manualno in (select manualno from #tempt3)

insert into Repertoy_package_materials_sum(PZHao,product_count,manualno)

select * from #tempt3

 end

else

  begin

  insert into Repertoy_package_materials_sum(PZHao,product_count,manualno)

select * from #tempt3

  end 

转载于:https://my.oschina.net/u/206098/blog/304153

你可能感兴趣的文章
优秀设计师是怎样炼成的?转自站酷 – 自由的猞猁 创作
查看>>
从本人做的安卓项目浅谈蓝牙(如有缺漏错误,还请指正)
查看>>
windows10 安装 vim +spf13
查看>>
bugfree中保存用例失败
查看>>
python学习笔记4-数据类型-数字
查看>>
nagios监控check_mysql报错:libmysqlclient.so.18: cannot open shared object file
查看>>
系统架构随笔 - 设计好每一款应用
查看>>
安装mysql过程
查看>>
/etc/profile和/etc/skel
查看>>
useradd命令中的-d参数不好用
查看>>
UIScrollView、UIPageControl的练习
查看>>
使用SHA-1摘要算法和证书链签名的软件包将不再被接受
查看>>
除百度、Google外其他蜘蛛IP封锁脚本
查看>>
迅雷面试行
查看>>
戴尔EqualLogic主机软件:新意何在?为何值得我关注?
查看>>
自制应用层协议的编写
查看>>
Python - 关于Python的变量
查看>>
解决exp无法导出问题
查看>>
XML(eXtensible Markup Language)速成
查看>>
自建框架-mf
查看>>