select d.lb as 类别,a.hh as 货号,d.pm as 品名,d.bm as 别名,a.kh as 位置,d.cd as 产地,d.gg as 规格, d.pdw as 剂型,b.sssl as 进货量,c.sl as 总销量,a.sjsl as 当前库存, d.cgry as 采购员,d.sx as 属性,d.jj as 进价,d.lsj as 零售价,isnull(f.sj,0) as 会员价
from ywbalance a
left join (select hh,sum(sssl) as sssl from rkdzk where (kdrq between '2009-4-1' and '2009-6-30') group by hh)
b on a.hh=b.hh
left join (select hh,sum(sl) as sl from fhdzk where (kdrq between '2009-4-1' and '2009-6-30')group by hh)
c on a.hh=c.hh
left join openrowset('sqloledb','192.168.0.100';'sa';'111','select * from knss2009.dbo.yw_kck')
d on a.hh=d.hhleft join openrowset('sqloledb','192.168.0.100';'sa';'111','select * from knss2009.dbo.GLMemberPrice') f on a.hh=f.hh
where (b.sssl>0 or c.sl>0) and fperiod='0' order by a.hh
这是我在公司用到的
我用的是openrowse函数
我感觉这个不错
代码有点多
不过原理很简单 |