您的位置:首页 > 其它

批次动销查询去物流

2016-05-19 10:52 267 查看
批次动销查询去物流
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  时空