title: Error while creating a view with procedure MySQL
body: <p>I have a problem when I try to create a view using a procedure. I have to do that because I need to make a pivot in MySQL, converting rows of a table in columns of another. 
  The query works great, but when I put it in the "CREATE VIEW" statement it gives me error. </p>
  
  <p>Here is the query with CREATE view</p>
  
  <pre><code>CREATE VIEW `Untitled` AS 
  SET @sql = NULL;
  SELECT
    GROUP_CONCAT(DISTINCT
      CONCAT(
        'MAX(IF(formazioni_persone.id_formazione = ',
        formazioni.id,
        ', true, false)) AS "',
        formazioni.titolo,'"'
      )
    ) INTO @sql
  FROM formazioni;
  
  SET @sql = CONCAT('SELECT persone.*, ', @sql, ' FROM persone INNER JOIN formazioni_persone ON persone.id = formazioni_persone.id_persona GROUP BY persone.id');
  
  PREPARE stmt1 FROM @sql; 
  
  EXECUTE stmt1; 
  
  DEALLOCATE PREPARE stmt1;
  </code></pre>
  
  <p>The query without CREATE VIEW <code>Untitled</code> AS  works great</p>
  
  <p>The query without CREATE VIEW <code>Untitled</code> AS  works great. I already tried to create a TEMP TABLE inside the CREATE VIEW, but nothing. Also tried to use delimiters like that, but nothing</p>
  
  <pre><code>DELIMITER $$ 
  CREATE VIEW `Untitled` AS 
  SET @sql = NULL;
  SELECT
    GROUP_CONCAT(DISTINCT
      CONCAT(
        'MAX(IF(formazioni_persone.id_formazione = ',
        formazioni.id,
        ', true, false)) AS "',
        formazioni.titolo,'"'
      )
    ) INTO @sql
  FROM formazioni;
  
  SET @sql = CONCAT('SELECT persone.*, ', @sql, ' FROM persone INNER JOIN formazioni_persone ON persone.id = formazioni_persone.id_persona GROUP BY persone.id');
  
  PREPARE stmt1 FROM @sql; 
  
  EXECUTE stmt1; 
  
  DEALLOCATE PREPARE stmt1;
  END $$ 
  DELIMITER ;
  </code></pre>
  
  <p>Error: 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 'SET @sql = NULL' at line 2, Time: 0.082000s</p>