批次动销查询去物流
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了批次动销查询去物流相关的知识,希望对你有一定的参考价值。
批次动销查询去物流
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
以上是关于批次动销查询去物流的主要内容,如果未能解决你的问题,请参考以下文章