MySQL存储过程刚刚停止工作

时间:2015-10-20 11:54:03

标签: mysql sql stored-procedures

我有以下存储过程设置,它在最近几天停止工作。有谁知道为什么这可能会停止工作?没有数据库表已更改。

    drop procedure if exists bookings_by_voucher;
    delimiter //
    create procedure bookings_by_voucher(in start_date date, in end_date date, l_id int)
    language sql
    deterministic
    sql security definer
    begin
            declare s text;
            select distinct group_concat(concat('sum(if(c.gross_value = ',gross_value,',c.net_value,0)) coupon',
                    cast(gross_value as unsigned))) from coupons into s;
            set @query = concat('select ',if(l_id is null, '"All Locations"','l.location_name'),
            ' location_name,ifnull(b.places, 0) as places, ',
            if(start_date is null and end_date is null,'"All Dates"',
            if(start_date is null, concat('" <= ',end_date,'"'),
            if(end_date is null,concat('" >= ',start_date,'"'),
            concat('"',start_date,' - ',end_date,'"')
            )
            )
            ),' dates,',
            ifnull(s,'"No Coupons"'),
            ',round(sum(b.price/1.2-ifnull(c.net_value,0)), 2) paidbycard from locations l join bookings b ',
            ' on l.id = b.location_id ',
            concat(if(start_date is null,'',concat(' and b.date >= "', start_date,'"'))),
            concat(if(end_date is null,'',concat(' and b.date <= "', end_date,'"'))),
            ' left join coupons c on b.voucher_code = c.code',
            if (l_id is null, ' group by l.id', concat(' where l.id = ', l_id) ));
            /*select @query;*/
            prepare stmt from @query;
            execute stmt;
    end//

我从我的应用程序(内置Laravel 5.1)中获取的错误是:

  

SQLSTATE [42000]:语法错误或访问冲突:1064您有   SQL语法错误;查看与您的手册相对应的手册   MySQL服务器版本,用于在“paybycard”附近使用正确的语法   从位置l加入预订b on l.id = b.location_id left join   &#39;在第1行(SQL:call bookings_by_voucher(null,null,null))

1 个答案:

答案 0 :(得分:0)

我找到了一些东西,如果我没有错,在你的“group by”条款之后有“where”条款。