create proc test
as
/* insert into tmptable incode,qty */
select his_ware.incode[1,1] as incode,his_ware.qty as qty from his_ware
where his_ware.chdate='12022003' and his_ware.incode='32080313'
go
/*这里是注释,我觉得可以将上述union中的结果集插入到一个临时的表中,然后再从表中选择数据时使用distinct 选项*/
语句为:
select his_ware.incode[1,1] as incode,his_ware.qty as qty from his_ware
where his_ware.chdate='12022003' and his_ware.incode='32080313'
union select his_gath.incode[1,2],sum(his_gath.sqty) as qty1 from his_gath
where incode='32080313' and dodate<='12022003'
group by incode,1 union select fjbh.gather_no[1,1],sum(fjbh.pickqty) as qty2 from fjbh
where fjbh.bh_date<='12022003' and fjbh.incode='32080313' and fjbh.workstat='1'
group by incode,1 union select uw_waretotray.goodsno[1,3],sum(uw_waretotray.sqty) as qty3 from uw_waretotray
where uw_waretotray.goodsno='32080313' and uw_waretotray.edodate <='12022003'
and uw_waretotray.stat='0'
group by uw_waretotray.goodsno,1 union select pick_full.incode[1,4],sum(pick_full.pickqty) as qty4 from pick_full
where pick_full.incode='32080313' and pick_full.pickdate<='12022003' and pick_full.workstat='4'
group by pick_full.incode,1
union select pick_refer.incode[1,5],sum(pick_refer.lastqty) as qty5 from pick_refer
where pick_refer.incode='32080313' and pick_refer.gather_no[1,8]<='20031202'
and pick_refer.workstat='5'
group by pick_refer.incode,1 union select picksh.printflag,sum(picksh.spickqty) as qty6 from picksh
where picksh.incode='32080313' and picksh.dodate<='12022003'
and picksh.pickflag='3' group by picksh.incode,1
union select othcase.gather_no[1,2],sum(othcase.pickqty) as qty7 from othcase
where othcase.incode='32080313' and othcase.pickdate<='12022003'
and othcase.workstat='5'
group by othcase.incode,1
union select order.merchan_no,sum(order.pickqty) as qty8 from order
where order.merchan_no[6,13]='32080313' and order.delivery_date<='20031202'
and pick_fg='Y'
group by order.merchan_no[6,13],1
union select flat.incode[1,6],sum(flat.pickqty) as qty9 from flat
where flat.pickdate<='12022003' and flat.incode='32080313'
and flat.workstat='5'
group by flat.incode,1
union select incode[1,7],sum(issu_qty) as qty10 from putorder
where gatherdate<='12022003' and incode='32080313' and hzstat='Y'
group by incode,1
union select incode[1,8],sum(spickqty) from movestock where incode='32080313'
and movedate<='12022003' and stat='1' group by 1,incode