Below is my store procedure .please help........
BEGIN
DECLARE selectQuery VARCHAR(2000);
declare finalquery varchar(2000);
declare stmt3 varchar(2000);
SET selectQuery = 'SELECT tbl_property.intId, strAddressLine1,(select strItemName from tbl_lk_item where intId=tbl_property.intPropertyCountyTypeId) as strCountyName ,(select strItemName from tbl_lk_item where intId=tbl_property.intPropertyCountryTypeId) as strCountryName ,strpostCode,(tbl_pro_adver_matchcriteria.floatAskingPrice),tbl_pro_adver_matchcriteria.intBedrooms
FROM tbl_property LEFT OUTER JOIN tbl_pro_adver_matchcriteria on tbl_property.intId = tbl_pro_adver_matchcriteria.intPro
set finalquery =CONCAT(selectQuery,strSqlQuery,' AND tbl_property.intId=1 ');
execute finalquery;
END
当我运行存储过程并传递参数“where tbl_property.intId=1”时,它给出了过程执行失败 1243 - 给 EXECUTE 的准备好的语句处理程序(最终查询)未知
好吧,我通过 select 语句检查查询结果,它给出了正确的查询并返回结果。所以请帮助我使用 Execute 语句。
最佳答案
感谢您的帮助,我已经尝试过了,只需稍加修改就可以使用。以下是我的存储过程:
BEGIN
DECLARE selectQuery VARCHAR(2000);
declare finalquery varchar(2000);
SET selectQuery = 'SELECT tbl_property.intId, strAddressLine1,(select strItemName from tbl_lk_item where intId=tbl_property.intPropertyCountyTypeId) as strCountyName ,(select strItemName from tbl_lk_item where intId=tbl_property.intPropertyCountryTypeId) as strCountryName ,strpostCode,(tbl_pro_adver_matchcriteria.floatAskingPrice),tbl_pro_adver_matchcriteria.intBedrooms
FROM tbl_property LEFT OUTER JOIN tbl_pro_adver_matchcriteria on tbl_property.intId = tbl_pro_adver_matchcriteria.intProId ';
set @finalquery =CONCAT(selectQuery,strSqlQuery,' AND tbl_property.intId=1 ');
PREPARE result from @finalquery;
EXECUTE result;
DEALLOCATE PREPARE result;
END
关于asp.net - 如何在使用动态where子句时在mysql中使用execute语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8971184/