需要这个简单任务的帮助。 此sp应该提供结果集,并将在MS-Access-Database报告中调用。
tablename是vvarying,但它以数字(lsid)结尾。使用Concatenatoin。 max_prepared_statement_count是默认值16382
有什么好主意吗?
THX 托马斯
CREATE DEFINER=`root2`@`%` PROCEDURE `sp_Quickview02`(IN lsid int)
BEGIN
set @tbl = concat('shape_tokens_',lsid); -- tablename
set @sql= 'select base.Status, count(base.token) as Anzahl
from (select ?.completed, if(?.completed = ''N'',''offen'', ''abgeschlossen'') as Status,
?.token from ?) base group by base.status;'
PREPARE stmt FROM @sql; -- error is thrown here
EXECUTE stmt using @tbl;
DEALLOCATE PREPARE stmt;
END
答案 0 :(得分:0)
如果检查变量@sql值,那么它将为您提供无法执行的输出,因此请更正。
SELECT base.Status, COUNT(base.token) AS Anzahl
FROM (SELECT ?.completed, IF(?.completed = 'N','offen', 'abgeschlossen') AS STATUS,
?.token FROM ?) base GROUP BY base.status;
按以下方式更改 -
CREATE DEFINER=`root2`@`%` PROCEDURE `sp_Quickview02`(IN lsid int)
BEGIN
set @tbl = concat('shape_tokens_',lsid); -- tablename
SET @sql= CONCAT('select base.Status, count(base.token) as Anzahl
from (select a.completed, if(a.completed = ''N'',''offen'', ''abgeschlossen'') as Status,
a.token from ',@tbl,' as a) base group by base.status;');
PREPARE stmt FROM @sql; -- error is thrown here
EXECUTE stmt using @tbl;
DEALLOCATE PREPARE stmt;
END
答案 1 :(得分:0)
查询需要4个参数,因此请使用执行查询,如下所示:
EXECUTE stmt using @tbl, @tbl, @tbl, @tbl;