壹佰网|ERP100 - 企业信息化知识门户

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 585|回复: 0

采购订单执行统计之入库未完成 SQL查询

[复制链接]
发表于 2012/9/21 13:50:27 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622  。

您需要 登录 才可以下载或查看,没有帐号?注册

x
/*经过多次沟通与试验
《采购订单执行统计之入库未完成 SQL查询》目前已基本完成了,而且我已通过服务器 建立存储过程与配置 sql mail 让服务器每天自动执行以下命令,并将结果导出为EXCEL文件 发给指定人员,以便跟踪采购订单的欠料情况。
*/
select f.cmemo AS 采购订单备注,f.cpoid AS 采购订单号,convert(char(10),f.dpodate,3) AS 采购日期,cast(d.iquantity as int) AS 采购数量,datediff(DAY,convert(varchar(10),b.dpodate,121),convert(varchar(10),getdate(),121))
,c.cpersonname AS 采购员,d.cinvcode AS 存货编码,h.cinvname AS 存货名称,
(case when d.cdefine22 is null then '-'else d.cdefine22 end) AS 存货自定义备注,i.cComUnitName AS 单位,g.cvenname AS 供应商名称,
(case when a.ccuscode is null then'-'else a.ccuscode end) AS 客户代码,cast(sum(isnull(e.iQuantity,0)) as int) as 入库数量,
(CASE WHEN a.Csocode is null then '-' else a.csocode end) AS 销售订单号
,(case when a.cmaker is null then '-' else a.cmaker end) AS 销售制单人
,(case when a.dpredatebt is null then '-' else convert(char(10),a.dpredatebt,3) end) as 预发货日期

from so_somain as a --销售订单主表
right JOIN CopyPOList as b ON a.csocode=b.csocode  --单据拷贝视图   销售订单号相等
inner join po_pomain as f on f.cpoid =b.cordercode  --采购订单主表  采购订单号相等
inner join person as c on c.cpersoncode=f.cpersoncode  --人员档案表  采购人员代码相等
inner join po_podetails as d on d.poid = f.poid  --采购订单子表  采购主表标识相等
left join rdrecords as e on e.iposid=d.id   --收发记录子表  采购子表标识相等
inner join Vendor as g on g.cvencode=f.cvencode  --供应商档案表  供应商代码相等
inner join inventory as h on h.cinvcode=d.cinvcode  --存货档案表  存货编码相等
inner join ComputationUnit as i on i.cComunitCode=h.cComunitCode  --计量单位档案表

Where --convert(char(10),b.dpodate,121)=convert(char(10),getdate()-15,3) and
(d.poid in (select poid from po_pomain where (poid in (select poid from po_podetails,rdrecords where
po_podetails.iQuantity>(select sum(rdrecords.iQuantity)
from rdrecords where rdrecords.iposid=po_podetails.id)
and POID IN (select poid from po_pomain where cState=1)))
or (poid in (select poid from po_podetails where id not in (select iposid from rdrecords where
id in (SELECT id FROM RDRECORD WHERE CSOURcE='采购到货单' ))))and cstate='1' ))
group by e.iposid,
f.cpoid
,a.ccuscode ,a.csocode  ,
a.cmaker,g.cvenname ,
c.cpersonname ,d.cinvcode ,h.cinvname ,
d.cdefine22 ,i.cComUnitName ,d.iquantity,
convert(char(10),f.dpodate,3) ,datediff(DAY,convert(varchar(10),b.dpodate,121),convert(varchar(10),getdate(),121)),f.cmemo,a.dpredatebt
order by f.cpoid

该贴已经同步到 chenchenjie的微博
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|手机版|壹佰网 ERP100 ( 京ICP备19053597号-2 )

Copyright © 2005-2012 北京海之大网络技术有限责任公司 服务器托管由互联互通
手机:13911575376
网站技术点击发送消息给对方83569622   广告&合作 点击发送消息给对方27675401   点击发送消息给对方634043306   咨询及人才点击发送消息给对方138011526

GMT+8, 2025/11/29 04:55 , Processed in 0.010880 second(s), 14 queries , File On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表