title: mysql error 'NULL' at line 1
body: <p>I got this error when tried to execute this:</p>
  
  <blockquote>
    <p>#1064 - 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 'NULL' at line 1</p>
  </blockquote>
  
  <p>Can't seems to find what is the problem. Appreciate if anyone can help</p>
  
  <pre class="lang-sql prettyprint-override"><code>SET @sql = NULL;
  
  SELECT
    GROUP_CONCAT(
      DISTINCT CONCAT (
        "SUM(IF(DATE(FROM_UNIXTIME(machine_stop)) = '",
        DATE(FROM_UNIXTIME(machine_stop)),"' ,
        (machine_start-machine_stop)/3600, 0)) AS ",
        DATE(FROM_UNIXTIME(machine_stop))
      )
    ) INTO @sql
  FROM
    downtime_data
  WHERE
    DATE(FROM_UNIXTIME(machine_stop)) &gt;= DATE(NOW()) - INTERVAL 7 DAY;
  
  SET @sql = CONCAT("SELECT
                       failure_code, ", @sql, " 
                     FROM
                       downtime_data 
                     WHERE
                       p.machine='HH1' AND
                       DATE(FROM_UNIXTIME(machine_stop)) &gt;= DATE(NOW()) - INTERVAL 7 DAY 
                     GROUP BY
                       failure_code,
                       DATE(FROM_UNIXTIME(machine_stop))"
                   );
  
  PREPARE stmt FROM @sql;
  EXECUTE stmt;
  DEALLOCATE PREPARE stmt;
  </code></pre>