存储过程问题,请大侠指导
在过程中,我有两个表,第1个是操作人的具体操作项目,第2个是操作的人(也就是姓名表),记录数不对等,如9个人只做1件事,那么第1个表(#d_sjtmp)只有1条记录,但第2个表(#D_xm)中就有9行记录,再如2个人做了5个项目,那么第1个表就有5条记录,但第2个表中只有2行记录,想插入或更新到另一个表(tb_工资日报_b)中,存储怎么写?select FCODE,DDH,bxcode,bxTHICK,bxWIDTH,bxLONGTH,,scthick,scwidth,sclongth,drscl into #d_sjtmp from tb_原始数据_b where flayer=3 And gx=@gx And rtrim(ltrim(jlsjh_tb_原始数据))=@jlsjh
alter table #d_sjtmp add [id] [int] IDENTITY(1,1)
alter table #d_sjtmp add [jlsjh_tb_工资日报] [char(20)]
update #d_sjtmp set jlsjh_tb_工资日报=@日报sjh
select @d_sjCount=max(id) from #d_sjtmp
set @d_sjRec=1
while @d_sjRec<=@d_sjCount
if @D_xmCount<=@d_sjCount
begin
insert into tb_工资日报_b select * from #d_sjtmp where id=@d_sjRec
if @d_sjRec<=@D_xmCount
update tb_工资日报_b set xm=(select 代单号1 from #D_xm where id=@d_sjRec),zbjt=(select 代单号2 from #D_xm where id=@d_sjRec),gzje=(select 单号3 from #D_xm where id=@d_sjRec)
set @d_sjRec=@d_sjRec+1
end
else if @D_xmCount>@d_sjCount
begin
。。。。。。。
end
end
Data.rar
(3.83 MB)
[此贴子已经被作者于2017-12-6 16:19编辑过]