CREATE  PROCEDURE sp_backproduct(in i int,in j int,in productName1 varchar(50),in busName1 varchar(50),in productType1 varchar(50),in state1 int)
begin
set @rownum=0;
set @a=i;
set @b=j;
set @w;
set @ismysql="select * from(select @rownum:=@rownum+1 AS rownum,mp.product_id as productId,product_name as productName, 
product_img as productImg, 
mb.business_name as busName,mpt.type_name as productType ,state
from mjl_business mb left JOIN mjl_business_product mbp 
on mb.id=mbp.business_id
left join mjl_product mp 
on mbp.product_id=mp.product_id
left join mjl_product_type mpt 
on mp.product_type=type_id
order by mp.show_date desc)aa where 1=1 ";
if(@productName1!=''&&@productName1!=null)
then  @ismysql=@ismysql+" and productName like '%"+productName1+"%' ";
if(@busName1!=''&&@busName1!=null)
then @ismysql=@ismysql+" and busName like '%"+busName1+"%' ";if(@productType1!=''&&@productType1!=null)
then @ismysql=@ismysql+" and productType like '%"+productType1+"%' ";if(@state1!=-1&&@state1!=null)
then @ismysql=@ismysql+" and state ="+state1;@ismysql=@ismysql+" limit ?,?";
prepare stmt from @ismysql;
execute stmt using @a,@b; 
deallocate prepare stmt;end;
个进行字符串拼接,不知道为什么错了,求帮助

解决方案 »

  1.   

    @ismysql=@ismysql+" limit ?,?";LIMIT 后不支持变量,你需要在字符串中处理一下。另外MYSQL的字符串拼接的方式是@ismysql=concat(@ismysql," limit ",@a,",",@b);
      

  2.   

    then @ismysql=@ismysql+" and productName like '%"+productName1+"%' ";->
    then @ismysql=concat(@ismysql,, and productName like \'%',+productName1,'%\'');
    @ismysql=@ismysql+" limit ?,?";
    ->
    @ismysql=concat(@ismysql,' limit ',@a,',',@b);
      

  3.   

    @ismysql=concat(@ismysql,'limit',@a,',',@b);
      

  4.   

    请参考这个http://doc.chinaunix.net/mysql/200811/206699.shtml