asp.net - 如何在使用动态where子句时在mysql中使用execute语句

标签 asp.net mysql

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/

相关文章:

c# - 带有依赖注入(inject)的 Telerik Reporting ObjectDataSource

c# - 在excel中扩展列的代码

mysql - CakePHP 模型在 SQL 语句中使用了错误的字段!

php - 今天的日期是否与数据库 PHP/MYSQL 中的现有范围相交

c# - 在编辑模式下动态更改 Gridview 列宽

c# - 拼写检查器有什么用?谷歌拼写检查器或 Hunspell

Asp.net 向所有页面添加 header 方法

php - Mysql查询用all_in_one seo帖子标题替换WP帖子标题

mysql - 将记录带入表 A 而不是带入表 B 左外连接

php - 热门用户 -> 评论 -> php