我
我来也
Unregistered / Unconfirmed
GUEST, unregistred user!
在Delphi 6中的问题。
用ADOConnection连接数据库。
用一个ADOQuery做Master;
用另一个ADOQuery做Detail;
中间用DataSource连接
在Detail的SQL中写入语句如下:
SELECT MB_XMMX.CPDM,MB_HS.XMMC,
SUM(MB_HS.SL) AS CL
,(SUM(MB_HS.SL)/412393) AS CPBZ
,(SUM(MB_HS.SL)/537940) AS CPL
,(CASE SUM(MB_HS.SL) WHEN 0 THEN 0 ELSE 1.1442*SUM(MB_HS.JE)/SUM(MB_HS.SL) END) AS DWCB
,(1.1442*SUM(MB_HS.JE)) AS CBJE
,(CASE SUM(MB_HS.SL) WHEN 0 THEN 0 ELSE SUM(MB_HS.JE)/SUM(MB_HS.SL) END) AS QSXSDJ
,SUM(MB_HS.JE) AS QSXSJE
FROM MB_HS
INNER JOIN FCBMMC ON FCBMMC.FCMC=MB_HS.FCMC
INNER JOIN MB_CJ ON MB_CJ.FCDM=FCBMMC.FCDM
AND MB_CJ.CJMC=MB_HS.CJMC
INNER JOIN MB_GX ON MB_GX.FCDM=FCBMMC.FCDM
AND MB_GX.CJBM=MB_CJ.CJBM
AND MB_GX.GXMC=MB_HS.GXMC
INNER JOIN MB_KM ON MB_KM.KMMC=MB_HS.KMMC
INNER JOIN MB_XM ON MB_XM.XMMC=MB_HS.XMMC
INNER JOIN MB_XMLX ON MB_XMLX.XMLXBM=MB_XM.XMLX
INNER JOIN MB_XMMX ON MB_XMMX.FCDM=FCBMMC.FCDM
AND MB_XMMX.CJBM=MB_CJ.CJBM
AND MB_XMMX.GXBM=MB_GX.GXBM
AND MB_XMMX.KMBM=MB_KM.KMBM
AND MB_XMMX.XMBM=MB_XM.XMBM
WHERE
MB_GX.GXBM<>'000'
AND MB_HS.KMMC='产成品'
AND MB_XMLX.XMLXMC='主产品'
AND MB_HS.JLDWMC='公斤'
AND MB_HS.RQ=:RQ
AND MB_HS.FCMC=:FCMC
AND MB_HS.CJMC=:CJMC
GROUP BY MB_XMMX.CPDM,MB_HS.XMMC
UNION ALL
SELECT MB_XMMX.CPDM,MB_HS.XMMC,
SUM(MB_HS.SL) AS CL
,(SUM(MB_HS.SL)/412393) AS CPBZ
,(SUM(MB_HS.SL)/537940) AS CPL
,(CASE SUM(MB_HS.SL) WHEN 0 THEN 0 ELSE 1.1442*SUM(MB_HS.JE)/SUM(MB_HS.SL) END) AS DWCB
,(1.1442*SUM(MB_HS.JE)) AS CBJE
,(CASE SUM(MB_HS.SL) WHEN 0 THEN 0 ELSE SUM(MB_HS.JE)/SUM(MB_HS.SL) END) AS QSXSDJ
,SUM(MB_HS.JE) AS QSXSJE
FROM MB_HS
INNER JOIN FCBMMC ON FCBMMC.FCMC=MB_HS.FCMC
INNER JOIN MB_CJ ON MB_CJ.FCDM=FCBMMC.FCDM
AND MB_CJ.CJMC=MB_HS.CJMC
INNER JOIN MB_GX ON MB_GX.FCDM=FCBMMC.FCDM
AND MB_GX.CJBM=MB_CJ.CJBM
AND MB_GX.GXMC=MB_HS.GXMC
INNER JOIN MB_KM ON MB_KM.KMMC=MB_HS.KMMC
INNER JOIN MB_XM ON MB_XM.XMMC=MB_HS.XMMC
INNER JOIN MB_XMLX ON MB_XMLX.XMLXBM=MB_XM.XMLX
INNER JOIN MB_XMMX ON MB_XMMX.FCDM=FCBMMC.FCDM
AND MB_XMMX.CJBM=MB_CJ.CJBM
AND MB_XMMX.GXBM=MB_GX.GXBM
AND MB_XMMX.KMBM=MB_KM.KMBM
AND MB_XMMX.XMBM=MB_XM.XMBM
WHERE
MB_GX.GXBM<>'000'
AND MB_HS.KMMC='产成品'
AND MB_XMLX.XMLXMC='膘油类'
AND MB_HS.JLDWMC='公斤'
AND MB_HS.RQ=:RQ
AND MB_HS.FCMC=:FCMC
AND MB_HS.CJMC=:CJMC
GROUP BY MB_XMMX.CPDM,MB_HS.XMMC
UNION ALL
SELECT MB_XMMX.CPDM,MB_HS.XMMC,
SUM(MB_HS.SL) AS CL
,(SUM(MB_HS.SL)/412393) AS CPBZ
,(SUM(MB_HS.SL)/537940) AS CPL
,(CASE SUM(MB_HS.SL) WHEN 0 THEN 0 ELSE 1.1442*SUM(MB_HS.JE)/SUM(MB_HS.SL) END) AS DWCB
,(1.1442*SUM(MB_HS.JE)) AS CBJE
,(CASE SUM(MB_HS.SL) WHEN 0 THEN 0 ELSE SUM(MB_HS.JE)/SUM(MB_HS.SL) END) AS QSXSDJ
,SUM(MB_HS.JE) AS QSXSJE
FROM MB_HS
INNER JOIN FCBMMC ON FCBMMC.FCMC=MB_HS.FCMC
INNER JOIN MB_CJ ON MB_CJ.FCDM=FCBMMC.FCDM
AND MB_CJ.CJMC=MB_HS.CJMC
INNER JOIN MB_GX ON MB_GX.FCDM=FCBMMC.FCDM
AND MB_GX.CJBM=MB_CJ.CJBM
AND MB_GX.GXMC=MB_HS.GXMC
INNER JOIN MB_KM ON MB_KM.KMMC=MB_HS.KMMC
INNER JOIN MB_XM ON MB_XM.XMMC=MB_HS.XMMC
INNER JOIN MB_XMLX ON MB_XMLX.XMLXBM=MB_XM.XMLX
INNER JOIN MB_XMMX ON MB_XMMX.FCDM=FCBMMC.FCDM
AND MB_XMMX.CJBM=MB_CJ.CJBM
AND MB_XMMX.GXBM=MB_GX.GXBM
AND MB_XMMX.KMBM=MB_KM.KMBM
AND MB_XMMX.XMBM=MB_XM.XMBM
WHERE
MB_GX.GXBM<>'000'
AND MB_HS.KMMC='产成品'
AND MB_XMLX.XMLXMC='分割类'
AND MB_HS.JLDWMC='公斤'
AND MB_HS.RQ=:RQ
AND MB_HS.FCMC=:FCMC
AND MB_HS.CJMC=:CJMC
GROUP BY MB_XMMX.CPDM,MB_HS.XMMC
单击“确认”,Delphi自动退出。
各位高手,救救我吧!
用ADOConnection连接数据库。
用一个ADOQuery做Master;
用另一个ADOQuery做Detail;
中间用DataSource连接
在Detail的SQL中写入语句如下:
SELECT MB_XMMX.CPDM,MB_HS.XMMC,
SUM(MB_HS.SL) AS CL
,(SUM(MB_HS.SL)/412393) AS CPBZ
,(SUM(MB_HS.SL)/537940) AS CPL
,(CASE SUM(MB_HS.SL) WHEN 0 THEN 0 ELSE 1.1442*SUM(MB_HS.JE)/SUM(MB_HS.SL) END) AS DWCB
,(1.1442*SUM(MB_HS.JE)) AS CBJE
,(CASE SUM(MB_HS.SL) WHEN 0 THEN 0 ELSE SUM(MB_HS.JE)/SUM(MB_HS.SL) END) AS QSXSDJ
,SUM(MB_HS.JE) AS QSXSJE
FROM MB_HS
INNER JOIN FCBMMC ON FCBMMC.FCMC=MB_HS.FCMC
INNER JOIN MB_CJ ON MB_CJ.FCDM=FCBMMC.FCDM
AND MB_CJ.CJMC=MB_HS.CJMC
INNER JOIN MB_GX ON MB_GX.FCDM=FCBMMC.FCDM
AND MB_GX.CJBM=MB_CJ.CJBM
AND MB_GX.GXMC=MB_HS.GXMC
INNER JOIN MB_KM ON MB_KM.KMMC=MB_HS.KMMC
INNER JOIN MB_XM ON MB_XM.XMMC=MB_HS.XMMC
INNER JOIN MB_XMLX ON MB_XMLX.XMLXBM=MB_XM.XMLX
INNER JOIN MB_XMMX ON MB_XMMX.FCDM=FCBMMC.FCDM
AND MB_XMMX.CJBM=MB_CJ.CJBM
AND MB_XMMX.GXBM=MB_GX.GXBM
AND MB_XMMX.KMBM=MB_KM.KMBM
AND MB_XMMX.XMBM=MB_XM.XMBM
WHERE
MB_GX.GXBM<>'000'
AND MB_HS.KMMC='产成品'
AND MB_XMLX.XMLXMC='主产品'
AND MB_HS.JLDWMC='公斤'
AND MB_HS.RQ=:RQ
AND MB_HS.FCMC=:FCMC
AND MB_HS.CJMC=:CJMC
GROUP BY MB_XMMX.CPDM,MB_HS.XMMC
UNION ALL
SELECT MB_XMMX.CPDM,MB_HS.XMMC,
SUM(MB_HS.SL) AS CL
,(SUM(MB_HS.SL)/412393) AS CPBZ
,(SUM(MB_HS.SL)/537940) AS CPL
,(CASE SUM(MB_HS.SL) WHEN 0 THEN 0 ELSE 1.1442*SUM(MB_HS.JE)/SUM(MB_HS.SL) END) AS DWCB
,(1.1442*SUM(MB_HS.JE)) AS CBJE
,(CASE SUM(MB_HS.SL) WHEN 0 THEN 0 ELSE SUM(MB_HS.JE)/SUM(MB_HS.SL) END) AS QSXSDJ
,SUM(MB_HS.JE) AS QSXSJE
FROM MB_HS
INNER JOIN FCBMMC ON FCBMMC.FCMC=MB_HS.FCMC
INNER JOIN MB_CJ ON MB_CJ.FCDM=FCBMMC.FCDM
AND MB_CJ.CJMC=MB_HS.CJMC
INNER JOIN MB_GX ON MB_GX.FCDM=FCBMMC.FCDM
AND MB_GX.CJBM=MB_CJ.CJBM
AND MB_GX.GXMC=MB_HS.GXMC
INNER JOIN MB_KM ON MB_KM.KMMC=MB_HS.KMMC
INNER JOIN MB_XM ON MB_XM.XMMC=MB_HS.XMMC
INNER JOIN MB_XMLX ON MB_XMLX.XMLXBM=MB_XM.XMLX
INNER JOIN MB_XMMX ON MB_XMMX.FCDM=FCBMMC.FCDM
AND MB_XMMX.CJBM=MB_CJ.CJBM
AND MB_XMMX.GXBM=MB_GX.GXBM
AND MB_XMMX.KMBM=MB_KM.KMBM
AND MB_XMMX.XMBM=MB_XM.XMBM
WHERE
MB_GX.GXBM<>'000'
AND MB_HS.KMMC='产成品'
AND MB_XMLX.XMLXMC='膘油类'
AND MB_HS.JLDWMC='公斤'
AND MB_HS.RQ=:RQ
AND MB_HS.FCMC=:FCMC
AND MB_HS.CJMC=:CJMC
GROUP BY MB_XMMX.CPDM,MB_HS.XMMC
UNION ALL
SELECT MB_XMMX.CPDM,MB_HS.XMMC,
SUM(MB_HS.SL) AS CL
,(SUM(MB_HS.SL)/412393) AS CPBZ
,(SUM(MB_HS.SL)/537940) AS CPL
,(CASE SUM(MB_HS.SL) WHEN 0 THEN 0 ELSE 1.1442*SUM(MB_HS.JE)/SUM(MB_HS.SL) END) AS DWCB
,(1.1442*SUM(MB_HS.JE)) AS CBJE
,(CASE SUM(MB_HS.SL) WHEN 0 THEN 0 ELSE SUM(MB_HS.JE)/SUM(MB_HS.SL) END) AS QSXSDJ
,SUM(MB_HS.JE) AS QSXSJE
FROM MB_HS
INNER JOIN FCBMMC ON FCBMMC.FCMC=MB_HS.FCMC
INNER JOIN MB_CJ ON MB_CJ.FCDM=FCBMMC.FCDM
AND MB_CJ.CJMC=MB_HS.CJMC
INNER JOIN MB_GX ON MB_GX.FCDM=FCBMMC.FCDM
AND MB_GX.CJBM=MB_CJ.CJBM
AND MB_GX.GXMC=MB_HS.GXMC
INNER JOIN MB_KM ON MB_KM.KMMC=MB_HS.KMMC
INNER JOIN MB_XM ON MB_XM.XMMC=MB_HS.XMMC
INNER JOIN MB_XMLX ON MB_XMLX.XMLXBM=MB_XM.XMLX
INNER JOIN MB_XMMX ON MB_XMMX.FCDM=FCBMMC.FCDM
AND MB_XMMX.CJBM=MB_CJ.CJBM
AND MB_XMMX.GXBM=MB_GX.GXBM
AND MB_XMMX.KMBM=MB_KM.KMBM
AND MB_XMMX.XMBM=MB_XM.XMBM
WHERE
MB_GX.GXBM<>'000'
AND MB_HS.KMMC='产成品'
AND MB_XMLX.XMLXMC='分割类'
AND MB_HS.JLDWMC='公斤'
AND MB_HS.RQ=:RQ
AND MB_HS.FCMC=:FCMC
AND MB_HS.CJMC=:CJMC
GROUP BY MB_XMMX.CPDM,MB_HS.XMMC
单击“确认”,Delphi自动退出。
各位高手,救救我吧!