New to asking questions, but have been using Stackoverflow for years.
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?
Current query:
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;
Any Assistance you can give would be greatly appreciated.
I am using SSMS 2012 running on 2008 SQL servers. The two linked servers are Oracle servers not able to be remote connected.