This code works in mySQL work bench
SET SESSION group_concat_max_len = 1000000;
SET @dynamic_columns = NULL;
SELECT GROUP_CONCAT(
DISTINCT CONCAT('MAX(CASE WHEN laps_cnt = "', laps_cnt, '" THEN TIME_FORMAT(lap_time, "%H %i %s") END) AS "', laps_cnt , '"') order by laps_cnt
) INTO @dynamic_columns
FROM rider_laps order by length( laps_cnt), laps_cnt;
SET @dynamic_sql = CONCAT(
'SELECT rider_id, ', @dynamic_columns, ' FROM rider_laps GROUP BY rider_id order by MAX( Lap_Time ) DESC'
);
PREPARE stmt FROM @dynamic_sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
But if i cut and paste into the SQLQuery SQL param it produces an error
'Error executing query: you have an error in your SQL syntax: check the manual that corresponds to your mySQL server version for the right syntax to use near 'SET @dynamic_columns = NULL;
How do I make it work ?