title: Insert result of executing dynamic query into a table
body: <p>I have a dynamic query <code>@strQuery</code> which on executing gives a result with lots of column.
  I want to insert the result from this dynamic query into a temporary table .
  I am doing this because I want to perform some filtering on the temporary table and get required result .</p>
  
  <p>A similar question was asked on previous thread <a href="https://stackoverflow.com/questions/662049/dynamic-sql-results-into-temp-table-in-sql-stored-procedure">HERE</a>
  in which a temporary table is created first and then data inserted using <code>INSERT INTO</code>.</p>
  
  <p>I want to avoid this step due to long list of columns and also the datatypes of fields is not known to me.</p>
  
  <pre><code>select * into #tmh from
  exec(@strQuery)
  </code></pre>
  
  <p><strong>Error Message</strong></p>
  
  <p><em>Incorrect syntax near the keyword 'exec'.</em></p>
  
  <p>How to do this ? Is it possible to be done in this way ? If not , please specify some other alternative to get store the result on executing dynamic query into a table.
  Thanks.</p>