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

【数据处理】循环插入每天销售数据

时间:2014-08-07 21:44:20      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:os   io   数据   2014   ar   .net   ad   ef   

declare @a datetime
set @a=‘20140630‘
while @a>=‘20140601‘
begin
INSERT INTO MDXS
SELECT PLUNO=A.PLUNO, PLUNAME=MAX(A.PLUNAME), QTY=SUM(A.QTY), NET=SUM(A.NET), DISAMT=SUM(A.DISAMT),SLAMT=SUM(A.SLAMT), ML=CASE WHEN MAX(B.PROP)=0 THEN SUM(A.NET)-SUM(A.QTY)*MAX(ISNULL(B.CURCSPRC,0))
WHEN MAX(B.PROP)<>0 THEN SUM(A.NET)*(MAX(B.PRCRAT)/100) END
,‘6015‘,@a
FROM
(select PLUNO=A.PLUNO, PLUNAME=A.PLUNAME, SPEC=A.SPEC, QTY=A.QTY, NET=A.NET, DISAMT=A.DISAMT,SLAMT=A.NET+A.DISAMT
from (select A.PLUNO, A.PLUNAME, A.SPEC, D.QTY, D.NET, D.DISAMT, D.PLUID, A.OPTID, A.DPTID, A.BNDID
from BASPLUCRTC A,
(
select B.PLUID, QTY=SUM(B.QTY), NET=SUM(B.AMT - B.DISAMT-ISNULL(B.DISC,0)), DISAMT=SUM(B.DISAMT+ISNULL(B.DISC,0))
from POSSRLBF C(NOLOCK), POSSRLDT B(NOLOCK)
where C.UID = B.UID and C.SLDAT >= DATEADD(day, -1, @a) and C.SLDAT <= @a and (C.FLAG = 1 or C.FLAG = 5) and B.ISDEL = 0
group by B.PLUID
) D
where A.PLUID = D.PLUID) A, BASPLUCRTC B, BASDEPT E
where A.PLUID=B.PLUID AND B.DPTID=E.ID
UNION ALL
SELECT PLUNO=A.PLUNO, PLUNAME=MAX(A.PLUNAME), SPEC=MAX(A.SPEC), QTY=SUM(B.QTY), NET=SUM(B.SLNET), DISAMT=SUM(B.DISAMT),SLAMT=SUM(B.SLAMT)
FROM DOC21BF C, DOC21DT B, BASPLUCRTC A, BASDEPT E
WHERE C.DOCNO=B.DOCNO AND B.PLUID=A.PLUID AND A.DPTID=E.ID
AND C.DOCDAT >= DATEADD(day, -1, @a) AND C.DOCDAT < @a
AND C.CTYP=1 AND ISNULL(C.RSV,0)=0 AND C.VALID=1
GROUP BY A.PLUNO
) A LEFT OUTER JOIN (SELECT PLUNO,CURCSPRC,PRCRAT,PROP FROM BASPLUMAIN A, BASPLUPRC B WHERE A.PLUID=B.PLUID) B ON A.PLUNO=B.PLUNO
GROUP BY A.PLUNO
set @a =dateadd(day,-1,@a)
end

 

【数据处理】循环插入每天销售数据,布布扣,bubuko.com

【数据处理】循环插入每天销售数据

标签:os   io   数据   2014   ar   .net   ad   ef   

原文地址:http://www.cnblogs.com/nlg3413/p/3897793.html

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