title: Select * into exec command doesn't work?
body: <p>I am using the <code>OPENROWSET</code> command to execute the query. </p>
  
  <p>I want the result value must be inserted into the temp table like</p>
  
  <pre><code>SELECT * INTO #TempTable EXEC @query
  </code></pre>
  
  <p>but it shows an error of </p>
  
  <blockquote>
    <p>An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.</p>
  </blockquote>
  
  <p>Can anyone tell me how can I execute the query and insert into temp table?</p>
  
  <p>The sample code is </p>
  
  <pre><code>declare @Query nvarchar(max)
  SET @Query ='SELECT 
                  *
              FROM
                  OPENROWSET
                  (
                          ''SQLNCLI'',
                          ''servername'';
                          ''db'';
                          ''pwd'',
                          ''set nocount on;
                          set fmtonly off;
                          exec databaseName.dbo.spname ''''param1 '''',''''param2'''',''''param3'''',''''param3''''  ''
                  )
                  '
  
  select * into #temp exec sp_executesql @Query
  </code></pre>