title: Stored Procedure with dynamic result into temp table
body: <p>I have a stored procedure in SQL 2014 that makes a dynamic query inside and return two static columns and the rest of columns are dynamic. If I need to put the result of my sp into a temp table, I need to create my temp table specifically with the name of the columns and data types.  </p>
  
  <p>How can I just put the result into a temp table without declaring the temp table? </p>
  
  <p>This is how I call it:</p>
  
  <pre><code>SELECT * INTO #TempTable 
  FROM OPENROWSET
  ('SQLNCLI','Server=cimplsql-d1.turtle.local;Trusted_Connection=yes;', 'EXEC [dbo].[AttributeSelect] ''2016-01-01'', ''2016-01-01'', 1')
  </code></pre>
  
  <p>I can't make my temp table well defined because the result is dynamic, it can return 4, 10 or 20 columns, I don't know.</p>
  
  <p>This is the error now:</p>
  
  <pre><code>The metadata could not be determined because statement 'EXEC SP_EXECUTESQL @Qry;' in procedure 'AttributeEntitiesSelect'  contains dynamic SQL.  Consider using the WITH RESULT SETS clause to explicitly describe the result set.
  </code></pre>
  
  <p>I used the option WITH RESULT SETS UNDEFINED on my dynamic sql inside the sp, but didn't work </p>