title: Use of CTE (WITH) in a MYSQL stored procedure
body: <p>I'm trying to use CTE for running the query below to avoid the "can't reopen the table xxxx' error in a MySQL stored procedure. MySQL Workbench claims a syntax error and doesn't allow to save the procedure. WITH is underlined in red and reads </p>
  
  <blockquote>
    <p>"With" is not valid a this position for this server version (8.0.13), expecting : CACHE, CHECKSUM, COMMIT.....</p>
  </blockquote>
  
  <pre><code>        ELSE
              -- Board charges
              WITH cte AS (SELECT id FROM billablehorses)
              INSERT INTO billablehorses 
              (id, horse, agrid, dos, months, installment, totalamount, billed, payableid)
              SELECT ah.id, h.name, a.id, ah.dos, 
              TIMESTAMPDIFF(MONTH, ah.dos, b.boardingdate) Months,
              p.amount,
              a.totalamount,
              TRUE,
              p.id
              FROM horses h 
              INNER JOIN agreementhorses ah
              ON h.id = ah.horseid
              INNER JOIN agreements a 
              ON ah.agreementid = a.id
              INNER JOIN payables p
              ON ah.id = p.agreementhorseid
              INNER JOIN boarding b
              ON p.ticketid = b.id
              WHERE p.typeid = 1
              AND ah.id IN (SELECT id FROM cte)
              AND EXISTS (SELECT id FROM billed WHERE id = ah.id);
              SET msg = CONCAT(ROW_COUNT() , " ", 'board charges inserted');
          END IF;
  </code></pre>