CREATE PROCEDURE sp_backproduct(in i int,in j int,in productName1 varchar(50),in busName1 varchar(50),in productType1 varchar(50))
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 state=1 ";if(productName1!=''&&productName1!=null)
then @ismysql=@ismysql+" and productName like '%"+productName1+"%' ";
end if
if(busName1!=''&&busName1!=null)
then @ismysql=@ismysql+" and busName like '%"+busName1+"%' ";
end if
if(productType1!=''&&productType1!=null)
then @ismysql=@ismysql+" and productType like '%"+productType1+"%' ";
end if
@ismysql=@ismysql+" limit ?,?";prepare stmt from @ismysql;
execute stmt using @a,@b;  
deallocate prepare stmt;end;就这个为什么会错呢,求大概例子,或则解决

解决方案 »

  1.   

    你select出来你最后的@ismysql  然后替换掉?  看看是否执行
      

  2.   


    主要是这个格式不知道怎么写错了,看了mysql手册也找不到什么有用信息,不加IF判断是没有问题的
      

  3.   

    在MYSQL中字符串相加 用CONCATif(productName1!=''&&productName1!=null)
    then @ismysql=CONCAT(@ismysql," and productName like '%",productName1,"%' ");
    end if
    其它的自行修改,在变量后面加SELECT 变量名,看看内容