title: Possible to use "INSERT INTO @VARIABLE EXEC() AT LINKED_SERVER" syntax? (SQL Server 2005)
body: <p>I am trying to execute a query on a linked server, but I need the results locally.</p>
  
  <pre><code>DECLARE @test TABLE
  (
  greeting CHAR(5)
  )
  
  INSERT INTO @test
  EXEC('select ''hello'' as greeting')
  
  SELECT * FROM @test
  </code></pre>
  
  <p>Uses an <code>EXEC()</code> and <code>INSERT INTO</code> but, obviously the query is executing locally.</p>
  
  <pre><code>DECLARE @test TABLE
  (
  greeting CHAR(5)
  )
  
  INSERT INTO @test
  EXEC('select ''hello'' as greeting') AT LINKED_SERVER
  
  SELECT * FROM @test
  </code></pre>
  
  <p>Does not work at all.</p>
  
  <p><code>SELECT greeting FROM OpenQuery(LINKED_SERVER,'SELECT''hello'' AS greeting')</code></p>
  
  <p>Accomplishes exactly what I want, but I need to be using a dynamic string, and the only way to make that work is to make my entire query a huge string and put it into an EXEC(), which I don't want to do since it is really ugly....</p>
  
  <p>Thanks for any help!</p>