title: Passing Variable list from one OpenQuery to another OpenQuery
body: <p>New to asking questions, but have been using Stackoverflow for years. </p>
  
  <p>I have two individually linked servers that do not speak to one another. I need to get a list of variables from one server into SQL and then pass that list of variables into the second OpenQuery with an end goal of bring the data from that server into SQL. I have been able to pass single keyed in variables. But when I try to use a stringed OpenQuery or just a stringed query it returns errors. Can someone point me in the right direction?</p>
  
  <p>Current query:</p>
  
  <pre><code>    DECLARE @string VARCHAR(MAX)
  ,       @SQL NVARCHAR(MAX);
  
  SET @string = 
  '
  Select 
      col1    
  from 
      OpenQuery(server1, ''Select col1 from table1 where col2 = '''' a ''''
      ';
  SET @SQL = 'SELECT * FROM OPENQUERY(Server2, ''SELECT * FROM table2 WHERE col1 = ''''' + @string  + ''''' '')';
  
  
  EXEC sp_executesql @string;
  </code></pre>
  
  <p>Any Assistance you can give would be greatly appreciated.</p>
  
  <p>I am using SSMS 2012 running on 2008 SQL servers. The two linked servers are Oracle servers not able to be remote connected.</p>