jeudi 7 novembre 2019

laravel stored procedure migration syntax error when calling

I have stored procedure migration in laravel for mysql DB.

This is the stored procedure:

DROP PROCEDURE IF EXISTS `select_total_raised_jobs`;
delimiter ;;
CREATE PROCEDURE `select_total_raised_jobs` (IN cid int)
BEGIN
    DROP TABLE IF EXISTS
    tmp_results;
    CREATE TEMPORARY TABLE tmp_results AS SELECT
        COUNT(jobs.id) AS TotalJobs,
        DATE(jobs.created_at) AS created_at,
        users.id AS userID,
        concat( users.first_name,' ',users.last_name) as full_name,
        jobs.driver_id AS jobsDriverID
    FROM `jobs`
    JOIN users ON users.driver_id = jobs.driver_id
    where users.company_id = cid and jobs.company_id = cid
    GROUP BY
        DATE(jobs.created_at),
        users.driver_id
    ORDER BY
        users.id ASC,jobs.created_at DESC;
    SELECT
        CONCAT("SELECT userID,full_name,",cores_by_dates," FROM tmp_results GROUP BY userID order by userID asc")
    INTO @query
    FROM
        (SELECT GROUP_CONCAT(CONCAT('IFNULL(MAX(CASE WHEN created_at=''',actual_date,''' THEN totalJobs END), ''-'') AS \"', col_name,'\"')) cores_by_dates
        FROM (SELECT actual_date,actual_date AS col_name FROM (SELECT DISTINCT created_at AS actual_date FROM tmp_results) AS dates) dates_with_col_names
    ) result;
    PREPARE statement FROM @query;
    EXECUTE statement;
    DEALLOCATE PREPARE statement;
    SET SESSION group_concat_max_len = 1000000;
END

it givens an below error when calling.

Syntax error near '' FROM tmp_results GROUP BY userID order by userID asc' at line 1

And feedback will be appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire