title: MySql: how to create temp table by using dynamic select statement?
body: <p>As you can understand from the title I want to create a temp table by using a dynamic select statement. Here is my codes:</p>
  
  <pre><code> declare  strwhere varchar(30);
  if hour(now()) &gt;= 16 and minute(now()) &gt;=30 then
      set strwhere = ' day(now()) +1 ';
  else 
      set strwhere = '  day(now()) ';
  end if;
  set @query = concat("select  pc.customerid,
                      deliverytimespanid,
                      pc.id,
                      ca.districtid,
                      pc.status,
                      pc.orderid,
                      deliverydatetime
                  from packages as pc
                  inner join  customeraddresses as ca on ca.id = pc.addressid
                  where pc.status = 1
                  and day(pc.deliverydatetime) =",strwhere,"
                  and month(pc.deliverydatetime) = month(now()) 
                  and year(pc.deliverydatetime) = year(now()) ");
  
  prepare resultset from @query;
  execute resultset;
  deallocate prepare resultset;
  create temporary table if not exists table2 as (select * from resultset);
  </code></pre>
  
  <p>It returns </p>
  
  <blockquote>
    <p>resultset doesn't exist.</p>
  </blockquote>
  
  <p>How should I select the result?</p>