不好意思,我sql不熟,之前没有描述清楚,现引用华海的代码将这一个问题进行说明一下,请注意以下红色字体
华海出有这样一段代码:(以下红色字体均为原access中的查询表,导入到sql表中后,ckkc,cymx考虑均以存储过程的方式进行重新定义)
原ckkc在sql的存储过程代码为:
create proc ckkc
as SELECT 货品编码,仓库, 方向,入库数量,出库数量 FROM CYMX
UNION ALL
SELECT 货品编码,仓库名称 AS 仓库,'入库' AS 方向,初始库存 AS 入库数量, '0' AS 出库数量 FROM 库存
--CYMX在access中又是另外一个查询表.到sql中CYMX重新定义为一个存储过程select ....from CYMA ,在这个存储过程中嵌套式的引用到另一个存储过程,不知道简单的复制过来,对不对
原cymx在sql的存储过程代码为,
create proc cymx
as
SELECT '0' AS 序号, 货品编码, 日期, 单号, 经办人, 仓库, 方向, 供应单位, 类型, 部门, 入库数量, 出库数量, 单价, 金额
FROM
(SELECT t.货品编码,n.日期,T.单号,N.经办人,n.原仓库 AS 仓库,'出库' AS 方向,'' as 供应单位,'调拨出库' AS 类型,'' AS 部门, '0' as 入库数量,t.数量 AS 出库数量,t.单价,t.金额 FROM 调拨明细 AS T LEFT JOIN 库存调拨 AS N ON t.单号 = n.单号
UNION ALL
SELECT t.货品编码,n.日期,T.单号,N.经办人,n.目的仓库 AS 仓库,'入库' AS 方向,'' as 供应单位,'调拨入库' AS 类型,'' AS 部门,t.数量 AS 入库数量, '0' as 出库数量,t.单价,t.金额 FROM 调拨明细 AS T LEFT JOIN 库存调拨 AS N ON t.单号 = n.单号
UNION ALL
SELECT t.货品编码,n.日期,T.单号,N.经办人,n.仓库名称 AS 仓库,'入库' AS 方向,'' as 供应单位,t.类型 AS 类型,'' AS 部门,t.盈 AS 入库数量, '0' as 出库数量,t.单价,t.金额 FROM 盘点明细 AS T LEFT JOIN 库存盘点 AS N ON t.单号 = n.单号 WHERE t.类型='盘盈'
UNION ALL
SELECT t.货品编码,n.日期,T.单号,N.经办人,n.仓库名称 AS 仓库,'出库' AS 方向,'' as 供应单位,t.类型 AS 类型,'' AS 部门, '0' AS 入库数量,t.亏 AS 出库数量,t.单价,t.金额 FROM 盘点明细 AS T LEFT JOIN 库存盘点 AS N ON t.单号 = n.单号 WHERE t.类型='盘亏'
UNION ALL
SELECT t.货品编码,n.日期,T.单号,N.经办人,n.仓库名称 AS 仓库,n.出入库 AS 方向,N.供应单位,N.类型 AS 类型,N.部门,t.数量 AS 入库数量, '0' as 出库数量,t.单价,t.金额 FROM 出入库明细 AS T LEFT JOIN 出入库 AS N ON t.单号 = n.单号 WHERE n.出入库='入库'
UNION ALL
SELECT t.货品编码,n.日期,T.单号,N.经办人,n.仓库名称 AS 仓库,n.出入库 AS 方向,N.供应单位,n.类型 AS 类型,N.部门, '0' AS 入库数量,t.数量 AS 出库数量,t.单价,t.金额 FROM 出入库明细 AS T LEFT JOIN 出入库 AS N ON t.单号 = n.单号 WHERE n.出入库='出库'). AS N
ORDER BY 日期
假设以上存储过程定义成功
在华海中一个窗口代码为: ckcc 、cymx均为存储过程名
SELECT '0' AS 序号, 库名, (SELECT COUNT(*) FROM
(SELECT DISTINCT 库名,货品编码 FROM CKKC,仓库信息 WHERE 仓库 = 库名) WHERE 库名 = M.库名) AS 商品种类,
(SELECT COUNT(*) FROM CYMX WHERE 方向='入库' AND 仓库 = M.库名 ) AS 本期入库_笔数,
(SELECT SUM(金额) FROM CYMX WHERE 方向='入库' AND 仓库 = M.库名 ) AS 本期入库_金额,
(SELECT COUNT(*) FROM CYMX WHERE 方向='出库' AND 仓库 = M.库名 ) AS 本期出库_笔数,
(SELECT Round(SUM(金额),2) FROM CYMX WHERE 方向='出库' AND 仓库 = M.库名 ) AS 本期出库_金额,
(SELECT COUNT(*) FROM CYMX WHERE 仓库 = M.库名 AND (类型='调拨入库' OR 类型='调拨出库') @#$) AS 本期调拨_笔数,
(SELECT COUNT(*) FROM CYMX WHERE 仓库 = M.库名 AND 类型='调拨入库' @#$) AS 本期调拨_调入笔数,
(SELECT COUNT(*) FROM CYMX WHERE 仓库 = M.库名 AND 类型='调拨出库' @#$) AS 本期调拨_调出笔数,
Round((SELECT SUM(金额) FROM CYMX WHERE 仓库 = M.库名 AND (类型='调拨入库' OR 类型='调拨出库') @#$),2) AS 本期调拨_金额,
(SELECT COUNT(*) FROM CYMX WHERE 仓库 = M.库名 AND (类型='盘盈' OR 类型='盘亏') @#$) AS 本期盘点_笔数,
(SELECT COUNT(*) FROM CYMX WHERE 仓库 = M.库名 AND 类型='盘盈' @#$) AS 本期盘点_盘盈笔数,
(SELECT COUNT(*) FROM CYMX WHERE 仓库 = M.库名 AND 类型='盘亏' @#$) AS 本期盘点_盘亏笔数,
Round((SELECT SUM(金额) FROM CYMX WHERE 仓库 = M.库名 AND (类型='盘盈' OR 类型='盘亏') @#$),2) AS 本期盘点_金额, '' AS 备注 FROM 仓库信息 AS M"
'入库汇总表'
这段代码中要调用cymx\ckkc这两个存储过程,单这样写 就可以调用吗
[此贴子已经被作者于2011-11-28 9:25:57编辑过]