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

各公司进价销价

时间:2016-09-24 13:53:23      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:时空

select zhspid,spgsh,hshj into gsjj from 

(select b.*,a.rq,a.djbh,a.hshj,row_number() over (PARTITION BY a.spid order by a.rq desc,a.djbh desc ) row 

from openrowset(‘SQLOLEDB‘, ‘60.220.254.22,2433‘; ‘SA‘; ‘zdyy0811.‘,ksoa.dbo.jh_rkmx) a,spkfkzh b

where a.djbh like ‘jha%‘ and a.spid=b.spid and b.spgsh=‘长治‘ and a.hshj>0) c

where row=1


insert into gsjj

select zhspid,spgsh,hshj from 

(select b.*,a.rq,a.djbh,a.hshj,row_number() over (PARTITION BY a.spid order by a.rq desc,a.djbh desc ) row 

from openrowset(‘SQLOLEDB‘,‘192.168.0.100‘; ‘SA‘; ‘‘,st_ccerp.dbo.ywmxk) a,spkfkzh b

where a.djbh like ‘jha%‘ and a.spid=b.spid and b.spgsh=‘大同‘ and a.hshj>0) c

where row=1


insert into gsjj

select zhspid,spgsh,hshj from 

(select b.*,a.rq,a.djbh,a.hshj,row_number() over (PARTITION BY a.spid order by a.rq desc,a.djbh desc ) row 

from openrowset(‘SQLOLEDB‘,‘192.168.10.222‘; ‘SA‘; ‘zdyy‘,ksoa.dbo.jh_rkmx) a,spkfkzh b

where a.djbh like ‘jha%‘ and a.spid=b.spid and b.spgsh=‘运城‘ and a.hshj>0) c

where row=1


insert into gsjj

select zhspid,spgsh,hshj from 

(select b.*,a.rq,a.djbh,a.hshj,row_number() over (PARTITION BY a.spid order by a.rq desc,a.djbh desc ) row 

from openrowset(‘SQLOLEDB‘,‘192.168.16.237‘; ‘SA‘; ‘zdyysm,.‘,ymksoa.dbo.jh_rkmx) a,spkfkzh b,openrowset(‘SQLOLEDB‘,‘192.168.16.237‘; ‘SA‘; ‘zdyysm,.‘,ymksoa.dbo.jh_rkhz) d

where a.djbh like ‘jha%‘ and a.spid=b.spid and b.spgsh=‘医贸‘ and a.hshj>0 and a.djbh=d.djbh and d.dwbh not in 

(select dwbh from openrowset(‘SQLOLEDB‘, ‘192.168.16.237‘; ‘SA‘; ‘zdyysm,.‘,ymksoa.dbo.mchk) where dwmch like ‘山西振东医药物流有限公司‘) 

) c

where row=1


select zhspid,spgsh,hshj from 

(select b.*,a.rq,a.djbh,a.hshj,row_number() over (PARTITION BY a.spid order by a.rq desc,a.djbh desc ) row 

from openrowset(‘SQLOLEDB‘,‘192.168.16.237‘; ‘SA‘; ‘zdyysm,.‘,ymksoa.dbo.jh_rkmx) a,spkfkzh b

where a.djbh like ‘jha%‘ and a.spid=b.spid and b.spgsh=‘医贸‘ and a.hshj>0 ) c

where row=1




select b.zhspid,b.spgsh,Convert(decimal(10,2),sum(a.hsje)/sum(a.shl)) hshj 

into gssj from openrowset(‘SQLOLEDB‘, ‘60.220.254.22,2433‘; ‘SA‘; ‘zdyy0811.‘,ksoa.dbo.pf_ckmx) a,spkfkzh b,

(select spid,rq,row_number() over (PARTITION BY spid order by rq desc,djbh desc ) row 

from openrowset(‘SQLOLEDB‘, ‘60.220.254.22,2433‘; ‘SA‘; ‘zdyy0811.‘,ksoa.dbo.pf_ckmx) ) c

where a.djbh like ‘xsa%‘ and a.spid=b.spid and b.spgsh=‘长治‘ and a.hshj>0 and a.spid=c.spid

and c.row=1 and a.rq>=convert(varchar(10),dateadd(month,-1,c.rq),120) and a.rq<=c.rq

group by b.zhspid,b.spgsh



insert into gssj

select b.zhspid,b.spgsh,Convert(decimal(10,2),sum(a.hsje)/sum(a.shl)) hshj 

from openrowset(‘SQLOLEDB‘,‘192.168.10.222‘; ‘SA‘; ‘zdyy‘,ksoa.dbo.pf_ckmx) a,spkfkzh b,

(select spid,rq,row_number() over (PARTITION BY spid order by rq desc,djbh desc ) row 

from openrowset(‘SQLOLEDB‘,‘192.168.10.222‘; ‘SA‘; ‘zdyy‘,ksoa.dbo.pf_ckmx) ) c

where a.djbh like ‘xsa%‘ and a.spid=b.spid and b.spgsh=‘运城‘ and a.hshj>0 and a.spid=c.spid

and c.row=1 and a.rq>=convert(varchar(10),dateadd(month,-1,c.rq),120) and a.rq<=c.rq

group by b.zhspid,b.spgsh


select spid,rq into #2 from 

(select spid,rq,row_number() over (PARTITION BY spid order by rq desc,djbh desc ) row 

from openrowset(‘SQLOLEDB‘, ‘192.168.0.100‘; ‘SA‘; ‘‘,st_ccerp.dbo.ywmxk)

)a

 where row=1

 

insert into gssj

select b.zhspid,b.spgsh,Convert(decimal(10,2),sum(a.hsje)/sum(a.shl)) hshj 

from openrowset(‘SQLOLEDB‘, ‘192.168.0.100‘; ‘SA‘; ‘‘,st_ccerp.dbo.ywmxk) a,spkfkzh b,#2 c

where a.djbh like ‘xsa%‘ and a.spid=b.spid and b.spgsh=‘大同‘ and a.hshj>0 and a.spid=c.spid

and a.rq>=convert(varchar(10),dateadd(month,-1,c.rq),120) and a.rq<=c.rq

group by b.zhspid,b.spgsh


select spid,rq into #1 from 

(select a.spid,a.rq,row_number() over (PARTITION BY a.spid order by a.rq desc,a.djbh desc ) row 

from openrowset(‘SQLOLEDB‘, ‘192.168.16.237‘; ‘SA‘; ‘zdyysm,.‘,ymksoa.dbo.pf_ckmx) a,openrowset(‘SQLOLEDB‘, ‘192.168.16.237‘; ‘SA‘; ‘zdyysm,.‘,ymksoa.dbo.pf_ckhz) b

where a.djbh=b.djbh and b.dwbh not in

(select dwbh from openrowset(‘SQLOLEDB‘, ‘192.168.16.237‘; ‘SA‘; ‘zdyysm,.‘,ymksoa.dbo.mchk) where dwmch like ‘山西振东医药物流有限公司‘) 

)c

 where row=1

 

insert into gssj

select b.zhspid,b.spgsh,Convert(decimal(10,2),sum(a.hsje)/sum(a.shl)) hshj 

from openrowset(‘SQLOLEDB‘,‘192.168.16.237‘; ‘SA‘; ‘zdyysm,.‘,ymksoa.dbo.pf_ckmx) a,spkfkzh b,#1 c,

openrowset(‘SQLOLEDB‘, ‘192.168.16.237‘; ‘SA‘; ‘zdyysm,.‘,ymksoa.dbo.pf_ckhz) d

where a.djbh like ‘xsa%‘ and a.spid=b.spid and b.spgsh=‘医贸‘ and a.hshj>0 and a.spid=c.spid

and a.rq>=convert(varchar(10),dateadd(month,-1,c.rq),120) and a.rq<=c.rq and a.djbh=d.djbh and d.dwbh not in

(select dwbh from openrowset(‘SQLOLEDB‘, ‘192.168.16.237‘; ‘SA‘; ‘zdyysm,.‘,ymksoa.dbo.mchk) where dwmch like ‘山西振东医药物流有限公司‘) 

group by b.zhspid,b.spgsh


各公司进价销价

标签:时空

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

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