码迷,mamicode.com
首页 > 其他好文 > 详细

批次动销查询去物流

时间:2016-05-19 13:26:18      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:时空

批次动销查询去物流

select a.spid,a.pici,sum(shl) shl into #1 from 
(select a.djbh,a.spid,a.pici,-a.shl as shl from pf_ckmx a,pf_ckhz b where a.djbh=b.djbh and a.djbh like ‘xs[a,c]%‘ and a.rq>=‘2016-04-20‘ and b.dwbh not in (select dwbh from mchk where dwmch=‘山西振东医药物流有限公司‘ and isxs=‘是‘)
union all
select a.djbh,a.spid,a.pici,a.shl from jh_rkmx a,jh_rkhz b where a.djbh=b.djbh and a.rq>=‘2016-04-20‘ and a.djbh like ‘jh[a,c]%‘) a
group by a.spid,a.pici
select spid,pici,sum(shl) shl into #2 from 
(select spid,批次 pici,数量 shl from fr_spkfk160421
union all
select spid,pici,shl from #1) a
group by spid,pici
select a.*,b.chbdj*a.shl chbje,c.bmgs
into #3 from #2 a
join spkfjc b on a.spid=b.spid
left join (select distinct bmgs,pici from sphwph where bmgs<>‘‘) c on a.pici=c.pici
select b.bmgs,f.ywlxr,a.spbh,a.spmch,a.shpgg,a.dw,a.jlgg,a.shengccj,f.pihao,f.baozhiqi,f.sxrq,c.rq as 采购日期,c.rkshl,c.rkshl-b.shl as 销量,b.shl,b.chbje,d.danwbh,d.dwmch,ltrim(rtrim(b.pici)) as pici
from #3 b
join spkfk a on a.spid=b.spid
join splsk c on c.djbh=left(b.pici,14) and c.dj_sn=replace(b.pici,left(b.pici,15),‘‘)
join mchk d on c.dwbh=d.dwbh
left join (select distinct pici,ywlxr,pihao,sxrq,baozhiqi from sphwph where ywlxr<>‘‘) f on b.pici=f.pici
where b.shl>0


批次动销查询去物流

标签:时空

原文地址:http://bks2015.blog.51cto.com/9847303/1774988

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!