懂
懂你
Unregistered / Unconfirmed
GUEST, unregistred user!
帮我倒这个程序吧!
简要:这个程序虽然乍看是很长,其实有很多部分是反复的。主要是多表连接问题。
要求:使用SQL2K编写存储过程。如果觉得烦,写出个轮廓也行。
程序如下:
*部门进销存
SELECT jxcqk22
ZAP
*起始日期
year1 = THISFORM.olecontrol1.YEAR
month1 = THISFORM.olecontrol1.MONTH
day1 = THISFORM.olecontrol1.DAY
date1 = CTOD(STR(year1) + STR(month1) + STR(day1))
*结束日期
year2 = THISFORM.olecontrol2.YEAR
month2 = THISFORM.olecontrol2.MONTH
day2 = THISFORM.olecontrol2.DAY
date2 = CTOD(STR(year2)+ STR(month2)+ STR(day2))
date0 = CTOD(STR(year1)+ STR(month1)+ '.01') &&月初日期
ny0 = SUBSTR(DTOC(date0 - 1),1,7) &&上月
nzero = EVALUATE("0." + REPLICATE('0', sys_sl)) &&零
a = nzero
b = 0.00
*部门进销存, 考虑调拨, 分单部门及多部门处理
*月初值
IF sys_cb = 0
SELECT bmkcbf.bmdm,bmkcbf.bysl AS sl,ROUND(bmkcbf.bysl*spdmbf.bykcpj,2) AS je,bmkcbf.spdm;
FROM bmkcbf ;
inner JOIN spdmbf;
ON bmkcbf.spdm=spdmbf.spdm;
WHERE bmkcbf.ny=ny0 AND spdmbf.ny=ny0;
INTO CURSOR temp1;
ORDER BY bmdm,bmkcbf.spdm
ELSE
SELECT bmkcbf.bmdm,bmkcbf.bysl AS sl,ROUND(bmkcbf.bysl*spdmbf.byydpj,2) AS je,bmkcbf.spdm;
FROM bmkcbf ;
inner JOIN spdmbf;
ON bmkcbf.spdm=spdmbf.spdm;
WHERE bmkcbf.ny=ny0 AND spdmbf.ny=ny0;
INTO CURSOR temp1;
ORDER BY bmdm,bmkcbf.spdm
ENDIF
*月初到date1发生数 第一部分
SELECT bmdm, sl, ROUND(dj*sl,2) AS je, spdm; &&(1)进货k+
FROM jhdj;
inner JOIN jhdjmx;
ON jhdj.djh=jhdjmx.djh ;
WHERE (rq >= date0) AND (rq < date1) AND !EMPTY(jhdj.sh);
UNION ALL;
SELECT bmdm, -sl AS sl, -ROUND(sl*jhj,2) AS je, spdm; &&(2)进货退货成本-
FROM jhthdj;
inner JOIN jhthdjmx;
ON jhthdj.djh=jhthdjmx.djh ;
WHERE (rq >= date0) AND (rq < date1) AND !EMPTY(jhthdj.sh);
INTO CURSOR temp2
_tally2 = _TALLY
*月初到date1发生数 第二部分
SELECT chbmdm AS bmdm, -sl AS sl,-ROUND(sl*dj,2) AS je, spdm ;&&(8) 调出-
FROM dbdj;
inner JOIN dbdjmx;
ON dbdj.djh=dbdjmx.djh ;
WHERE (rq >= date0) AND (rq < date1) AND !EMPTY(dbdj.sh);
UNION ALL;
SELECT bmdm, -sl AS sl,-ROUND(sl*jhj,2) AS je, spdm; &&(9) 领用+
FROM lydj;
inner JOIN lydjmx;
ON lydj.djh=lydjmx.djh ;
WHERE (rq >= date0) AND (rq < date1) AND !EMPTY(lydj.sh);
INTO CURSOR temp3
_tally3 = _TALLY
DO CASE
CASE (_tally2 = 0) AND (_tally3 = 0)
SELECT * FROM temp1;
INTO CURSOR temp4
CASE (_tally2 <> 0) AND (_tally3 <> 0)
SELECT * FROM temp3;
UNION ALL;
SELECT * FROM temp2;
UNION ALL;
SELECT * FROM temp1;
INTO CURSOR temp4
CASE _tally2 <> 0
SELECT * FROM temp2;
UNION ALL;
SELECT *FROM temp1;
INTO CURSOR temp4
CASE _tally3 <> 0
SELECT * FROM temp3;
UNION ALL;
SELECT * FROM temp1;
INTO CURSOR temp4
ENDCASE
*得期初值
SELECT bmdm, SUM(sl) AS sl, SUM(je) AS je ,spdm ;
FROM temp4 ;
GROU BY spdm,bmdm ;
INTO CURSOR temp
*date1 到 date2 发生数
SELECT bmdm,spdm,temp.sl AS mqkczs,ROUND(je,2) AS je,a AS jhsl,b AS jhje,a AS jhthsl,;
b AS jhthje,b AS jhthcb,a AS xssl,b AS xsje,b AS xscb,a AS xsthsl,b AS xsthje,;
a AS lysl,b AS lyje,b AS lycb,a AS bssl,b AS bsje,a AS bysl,b AS byje,a AS zzsl,;
b AS zzje,a AS cxsl,b AS cxje,a AS zzsl1,b AS zzje1,a AS cxsl1,b AS cxje1,;
a AS djsl,b AS djje ,a AS dcsl,b AS dcje ;
FROM temp; &&(1)取期初值
UNION ALL;
SELECT bmdm,spdm,a AS mqkczs,b AS je,sl AS jhsl,ROUND(sl*dj,2) AS jhje,a AS jhthsl,;
b AS jhthje,b AS jhthcb,a AS xssl,b AS xsje,b AS xscb,a AS xsthsl,b AS xsthje,;
a AS lysl,b AS lyje,b AS lycb,a AS bssl,b AS bsje,a AS bysl,b AS byje,a AS zzsl,;
b AS zzje,a AS cxsl,b AS cxje,a AS zzsl1,b AS zzje1,a AS cxsl1,b AS cxje1,;
a AS djsl,b AS djje,a AS dcsl,b AS dcje ;
FROM jhdj inner JOIN jhdjmx ON jhdj.djh=jhdjmx.djh ;
WHERE BETWEEN(jhdj.rq,date1,date2) AND !EMPTY(jhdj.sh); &&(2)进货发生数
UNION ALL;
SELECT bmdm,spdm,a AS mqkczs,b AS je,a AS jhsl,b AS jhje,sl AS jhthsl, ;
ROUND(sl*dj,2) AS jhthje,ROUND(sl*jhj,2) AS jhthcb,a AS xssl,b AS xsje,b AS xscb,;
a AS xsthsl,b AS xsthje,a AS lysl,b AS lyje,b AS lycb,a AS bssl,b AS bsje,a AS bysl,;
b AS byje,a AS zzsl,b AS zzje,a AS cxsl,b AS cxje,a AS zzsl1,b AS zzje1,a AS cxsl1,;
b AS cxje1,a AS djsl,b AS djje,a AS dcsl,b AS dcje ;
FROM jhthdj inner JOIN jhthdjmx ON jhthdj.djh=jhthdjmx.djh ;
WHERE BETWEEN(jhthdj.rq,date1,date2) AND !EMPTY(jhthdj.sh); &&(3)退货发生数
INTO CURSOR temp8
SELECT * FROM temp8;
UNION ALL;
SELECT chbmdm AS bmdm,spdm,a AS mqkczs,b AS je,a AS jhsl,b AS jhje,a AS jhthsl,;
b AS jhthje,b AS jhthcb,a AS xssl,b AS xsje,b AS xscb, a AS xsthsl,b AS xsthje,;
a AS lysl,b AS lyje,b AS lycb,a AS bssl,b AS bsje,a AS bysl,b AS byje,a AS zzsl,;
b AS zzje,a AS cxsl,b AS cxje,a AS zzsl1,b AS zzje1,a AS cxsl1,b AS cxje1,;
a AS djsl,b AS djje,sl AS dcsl,ROUND(sl*dj,2) AS dcje ;
FROM dbdj inner JOIN dbdjmx ON dbdj.djh=dbdjmx.djh ;
WHERE BETWEEN(dbdj.rq,date1,date2) AND !EMPTY(dbdj.sh); &&(8)调出发生数
UNION ALL;
SELECT bmdm,spdm,a AS mqkczs,b AS je,a AS jhsl,b AS jhje,a AS jhthsl,b AS jhthje,;
b AS jhthcb,a AS xssl,b AS xsje,b AS xscb,a AS xsthsl,b AS xsthje,a AS lysl,b AS lyje,;
b AS lycb,a AS bssl,b AS bsje,sl AS bysl,ROUND(sl*dj,2) AS byje,a AS zzsl,b AS zzje,;
a AS cxsl,b AS cxje,a AS zzsl1,b AS zzje1,a AS cxsl1,b AS cxje1,;
a AS djsl,b AS djje,a AS dcsl,b AS dcje;
FROM bydj inner JOIN bydjmx ON bydj.djh=bydjmx.djh ;
WHERE BETWEEN(bydj.rq,date1,date2) AND !EMPTY(bydj.sh); &&(9)报溢发生数
INTO CURSOR temp5
IF _TALLY<>0
*分组合计
SELECT bmdm, spdm,SUM(mqkczs) AS zs,SUM(je) AS zje, SUM(jhsl) AS jhsl, SUM(jhje) AS jhje, ;
SUM(jhthsl) AS jhthsl,SUM(jhthje) AS jhthje, SUM(jhthcb) AS jhthcb, SUM(cxsl) AS cxsl, ;
SUM(cxje) AS cxje,SUM(xssl) AS xssl, SUM(xsje) AS xsje,SUM(xscb) AS xscb, ;
SUM(xsthsl) AS xsthsl, SUM(xsthje) AS xsthje, SUM(zzsl) AS zzsl, SUM(zzje)AS zzje, ;
SUM(lysl) AS lysl,SUM(lyje) AS lyje, SUM(lycb) AS lycb,SUM(zzsl1) AS zzsl1,;
SUM(zzje1) AS zzje1,SUM(cxsl1) AS cxsl1, SUM(cxje1) AS cxje1,SUM(bysl-bssl) AS sysl,;
SUM(byje-bsje) AS syje, SUM(djsl) AS djsl,SUM(djje) AS djje,SUM(dcsl) AS dcsl,SUM(dcje) AS dcje;
FROM temp5 GROUP BY spdm,bmdm INTO CURSOR temp6
*连接部门名称、商品名称
SELECT temp6.bmdm,bmmc,temp6.spdm,spmc,jldw,zs,zje,jhsl,jhje,jhthsl,jhthje,;
jhthcb,cxsl,cxje,xssl,xsje,xscb, xsthsl, xsthje,zzsl,zzje, lysl, lyje, ;
lycb, zzsl1,zzje1,cxsl1,cxje1,sysl,syje,spdm.bykcpj,djsl,djje,dcsl,dcje,;
ROUND((zs+jhsl-jhthsl+cxsl-xssl+xsthsl-zzsl-lysl+zzsl1-cxsl1+sysl+djsl-dcsl),sys_sl) AS rsl,;
ROUND((zje+jhje-jhthcb+cxje-xscb+xsthje-zzje-lycb+zzje1-cxje1+syje+djje-dcje),2) AS rje;
FROM temp6 inner JOIN spdm;
ON temp6.spdm=spdm.spdm;
inner JOIN bm;
ON temp6.bmdm=bm.bmdm;
INTO CURSOR jxcqk2_t;
ORDER BY temp6.bmdm,temp6.spdm
ENDIF
SELECT jxcqk22
GO TOP
简要:这个程序虽然乍看是很长,其实有很多部分是反复的。主要是多表连接问题。
要求:使用SQL2K编写存储过程。如果觉得烦,写出个轮廓也行。
程序如下:
*部门进销存
SELECT jxcqk22
ZAP
*起始日期
year1 = THISFORM.olecontrol1.YEAR
month1 = THISFORM.olecontrol1.MONTH
day1 = THISFORM.olecontrol1.DAY
date1 = CTOD(STR(year1) + STR(month1) + STR(day1))
*结束日期
year2 = THISFORM.olecontrol2.YEAR
month2 = THISFORM.olecontrol2.MONTH
day2 = THISFORM.olecontrol2.DAY
date2 = CTOD(STR(year2)+ STR(month2)+ STR(day2))
date0 = CTOD(STR(year1)+ STR(month1)+ '.01') &&月初日期
ny0 = SUBSTR(DTOC(date0 - 1),1,7) &&上月
nzero = EVALUATE("0." + REPLICATE('0', sys_sl)) &&零
a = nzero
b = 0.00
*部门进销存, 考虑调拨, 分单部门及多部门处理
*月初值
IF sys_cb = 0
SELECT bmkcbf.bmdm,bmkcbf.bysl AS sl,ROUND(bmkcbf.bysl*spdmbf.bykcpj,2) AS je,bmkcbf.spdm;
FROM bmkcbf ;
inner JOIN spdmbf;
ON bmkcbf.spdm=spdmbf.spdm;
WHERE bmkcbf.ny=ny0 AND spdmbf.ny=ny0;
INTO CURSOR temp1;
ORDER BY bmdm,bmkcbf.spdm
ELSE
SELECT bmkcbf.bmdm,bmkcbf.bysl AS sl,ROUND(bmkcbf.bysl*spdmbf.byydpj,2) AS je,bmkcbf.spdm;
FROM bmkcbf ;
inner JOIN spdmbf;
ON bmkcbf.spdm=spdmbf.spdm;
WHERE bmkcbf.ny=ny0 AND spdmbf.ny=ny0;
INTO CURSOR temp1;
ORDER BY bmdm,bmkcbf.spdm
ENDIF
*月初到date1发生数 第一部分
SELECT bmdm, sl, ROUND(dj*sl,2) AS je, spdm; &&(1)进货k+
FROM jhdj;
inner JOIN jhdjmx;
ON jhdj.djh=jhdjmx.djh ;
WHERE (rq >= date0) AND (rq < date1) AND !EMPTY(jhdj.sh);
UNION ALL;
SELECT bmdm, -sl AS sl, -ROUND(sl*jhj,2) AS je, spdm; &&(2)进货退货成本-
FROM jhthdj;
inner JOIN jhthdjmx;
ON jhthdj.djh=jhthdjmx.djh ;
WHERE (rq >= date0) AND (rq < date1) AND !EMPTY(jhthdj.sh);
INTO CURSOR temp2
_tally2 = _TALLY
*月初到date1发生数 第二部分
SELECT chbmdm AS bmdm, -sl AS sl,-ROUND(sl*dj,2) AS je, spdm ;&&(8) 调出-
FROM dbdj;
inner JOIN dbdjmx;
ON dbdj.djh=dbdjmx.djh ;
WHERE (rq >= date0) AND (rq < date1) AND !EMPTY(dbdj.sh);
UNION ALL;
SELECT bmdm, -sl AS sl,-ROUND(sl*jhj,2) AS je, spdm; &&(9) 领用+
FROM lydj;
inner JOIN lydjmx;
ON lydj.djh=lydjmx.djh ;
WHERE (rq >= date0) AND (rq < date1) AND !EMPTY(lydj.sh);
INTO CURSOR temp3
_tally3 = _TALLY
DO CASE
CASE (_tally2 = 0) AND (_tally3 = 0)
SELECT * FROM temp1;
INTO CURSOR temp4
CASE (_tally2 <> 0) AND (_tally3 <> 0)
SELECT * FROM temp3;
UNION ALL;
SELECT * FROM temp2;
UNION ALL;
SELECT * FROM temp1;
INTO CURSOR temp4
CASE _tally2 <> 0
SELECT * FROM temp2;
UNION ALL;
SELECT *FROM temp1;
INTO CURSOR temp4
CASE _tally3 <> 0
SELECT * FROM temp3;
UNION ALL;
SELECT * FROM temp1;
INTO CURSOR temp4
ENDCASE
*得期初值
SELECT bmdm, SUM(sl) AS sl, SUM(je) AS je ,spdm ;
FROM temp4 ;
GROU BY spdm,bmdm ;
INTO CURSOR temp
*date1 到 date2 发生数
SELECT bmdm,spdm,temp.sl AS mqkczs,ROUND(je,2) AS je,a AS jhsl,b AS jhje,a AS jhthsl,;
b AS jhthje,b AS jhthcb,a AS xssl,b AS xsje,b AS xscb,a AS xsthsl,b AS xsthje,;
a AS lysl,b AS lyje,b AS lycb,a AS bssl,b AS bsje,a AS bysl,b AS byje,a AS zzsl,;
b AS zzje,a AS cxsl,b AS cxje,a AS zzsl1,b AS zzje1,a AS cxsl1,b AS cxje1,;
a AS djsl,b AS djje ,a AS dcsl,b AS dcje ;
FROM temp; &&(1)取期初值
UNION ALL;
SELECT bmdm,spdm,a AS mqkczs,b AS je,sl AS jhsl,ROUND(sl*dj,2) AS jhje,a AS jhthsl,;
b AS jhthje,b AS jhthcb,a AS xssl,b AS xsje,b AS xscb,a AS xsthsl,b AS xsthje,;
a AS lysl,b AS lyje,b AS lycb,a AS bssl,b AS bsje,a AS bysl,b AS byje,a AS zzsl,;
b AS zzje,a AS cxsl,b AS cxje,a AS zzsl1,b AS zzje1,a AS cxsl1,b AS cxje1,;
a AS djsl,b AS djje,a AS dcsl,b AS dcje ;
FROM jhdj inner JOIN jhdjmx ON jhdj.djh=jhdjmx.djh ;
WHERE BETWEEN(jhdj.rq,date1,date2) AND !EMPTY(jhdj.sh); &&(2)进货发生数
UNION ALL;
SELECT bmdm,spdm,a AS mqkczs,b AS je,a AS jhsl,b AS jhje,sl AS jhthsl, ;
ROUND(sl*dj,2) AS jhthje,ROUND(sl*jhj,2) AS jhthcb,a AS xssl,b AS xsje,b AS xscb,;
a AS xsthsl,b AS xsthje,a AS lysl,b AS lyje,b AS lycb,a AS bssl,b AS bsje,a AS bysl,;
b AS byje,a AS zzsl,b AS zzje,a AS cxsl,b AS cxje,a AS zzsl1,b AS zzje1,a AS cxsl1,;
b AS cxje1,a AS djsl,b AS djje,a AS dcsl,b AS dcje ;
FROM jhthdj inner JOIN jhthdjmx ON jhthdj.djh=jhthdjmx.djh ;
WHERE BETWEEN(jhthdj.rq,date1,date2) AND !EMPTY(jhthdj.sh); &&(3)退货发生数
INTO CURSOR temp8
SELECT * FROM temp8;
UNION ALL;
SELECT chbmdm AS bmdm,spdm,a AS mqkczs,b AS je,a AS jhsl,b AS jhje,a AS jhthsl,;
b AS jhthje,b AS jhthcb,a AS xssl,b AS xsje,b AS xscb, a AS xsthsl,b AS xsthje,;
a AS lysl,b AS lyje,b AS lycb,a AS bssl,b AS bsje,a AS bysl,b AS byje,a AS zzsl,;
b AS zzje,a AS cxsl,b AS cxje,a AS zzsl1,b AS zzje1,a AS cxsl1,b AS cxje1,;
a AS djsl,b AS djje,sl AS dcsl,ROUND(sl*dj,2) AS dcje ;
FROM dbdj inner JOIN dbdjmx ON dbdj.djh=dbdjmx.djh ;
WHERE BETWEEN(dbdj.rq,date1,date2) AND !EMPTY(dbdj.sh); &&(8)调出发生数
UNION ALL;
SELECT bmdm,spdm,a AS mqkczs,b AS je,a AS jhsl,b AS jhje,a AS jhthsl,b AS jhthje,;
b AS jhthcb,a AS xssl,b AS xsje,b AS xscb,a AS xsthsl,b AS xsthje,a AS lysl,b AS lyje,;
b AS lycb,a AS bssl,b AS bsje,sl AS bysl,ROUND(sl*dj,2) AS byje,a AS zzsl,b AS zzje,;
a AS cxsl,b AS cxje,a AS zzsl1,b AS zzje1,a AS cxsl1,b AS cxje1,;
a AS djsl,b AS djje,a AS dcsl,b AS dcje;
FROM bydj inner JOIN bydjmx ON bydj.djh=bydjmx.djh ;
WHERE BETWEEN(bydj.rq,date1,date2) AND !EMPTY(bydj.sh); &&(9)报溢发生数
INTO CURSOR temp5
IF _TALLY<>0
*分组合计
SELECT bmdm, spdm,SUM(mqkczs) AS zs,SUM(je) AS zje, SUM(jhsl) AS jhsl, SUM(jhje) AS jhje, ;
SUM(jhthsl) AS jhthsl,SUM(jhthje) AS jhthje, SUM(jhthcb) AS jhthcb, SUM(cxsl) AS cxsl, ;
SUM(cxje) AS cxje,SUM(xssl) AS xssl, SUM(xsje) AS xsje,SUM(xscb) AS xscb, ;
SUM(xsthsl) AS xsthsl, SUM(xsthje) AS xsthje, SUM(zzsl) AS zzsl, SUM(zzje)AS zzje, ;
SUM(lysl) AS lysl,SUM(lyje) AS lyje, SUM(lycb) AS lycb,SUM(zzsl1) AS zzsl1,;
SUM(zzje1) AS zzje1,SUM(cxsl1) AS cxsl1, SUM(cxje1) AS cxje1,SUM(bysl-bssl) AS sysl,;
SUM(byje-bsje) AS syje, SUM(djsl) AS djsl,SUM(djje) AS djje,SUM(dcsl) AS dcsl,SUM(dcje) AS dcje;
FROM temp5 GROUP BY spdm,bmdm INTO CURSOR temp6
*连接部门名称、商品名称
SELECT temp6.bmdm,bmmc,temp6.spdm,spmc,jldw,zs,zje,jhsl,jhje,jhthsl,jhthje,;
jhthcb,cxsl,cxje,xssl,xsje,xscb, xsthsl, xsthje,zzsl,zzje, lysl, lyje, ;
lycb, zzsl1,zzje1,cxsl1,cxje1,sysl,syje,spdm.bykcpj,djsl,djje,dcsl,dcje,;
ROUND((zs+jhsl-jhthsl+cxsl-xssl+xsthsl-zzsl-lysl+zzsl1-cxsl1+sysl+djsl-dcsl),sys_sl) AS rsl,;
ROUND((zje+jhje-jhthcb+cxje-xscb+xsthje-zzje-lycb+zzje1-cxje1+syje+djje-dcje),2) AS rje;
FROM temp6 inner JOIN spdm;
ON temp6.spdm=spdm.spdm;
inner JOIN bm;
ON temp6.bmdm=bm.bmdm;
INTO CURSOR jxcqk2_t;
ORDER BY temp6.bmdm,temp6.spdm
ENDIF
SELECT jxcqk22
GO TOP