0

需要幫助在這個簡單的任務。 這個sp應該提供一個結果集,並且會在MS-Access-Database報告中調用。準備stmt行thorws錯誤

表名是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

如果您檢查您的變量值@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 
0

查詢期待4參數所以使用執行查詢,如下給出:

EXECUTE stmt using @tbl, @tbl, @tbl, @tbl;