You can do:
CREATE TABLE #temp (...)
INSERT TABLE #temp
EXEC (@strSQL) at LinkedServer
Yes, you need to create the table beforehand.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I need to query a linked server using OpenQuery () and then store the results into a temp table. I don't have any problems doing this when the query is under the 8000 character limit, but now I have one that exceeds the limit as it is 17,559 characters. So, I have employed the solution shown below and the query runs fine. Now, I need help with how to adjust the script to store the results into a temp table, preferably using Select * Into so I can further manipulate the data.
Declare @strSQL varchar(max)
set @strSQL = N'<your query here>'
exec @strSQL at <YourLinkedServerName>
Thanks
Lorjust
You can do:
CREATE TABLE #temp (...)
INSERT TABLE #temp
EXEC (@strSQL) at LinkedServer
Yes, you need to create the table beforehand.
Hi there,
If you would like to store dynamic SQL results into # temporary table or a a table variable, you have to declare the DDL first.
The below article has a sample script that might help you out.
https://learn.microsoft.com/en-us/answers/questions/257458/how-can-i-insert-dynamic-sql-data-into-temp-table.html
------------------------------------------------------------------------------------------------------------------------------
--If the reply is helpful, please Upvote and Accept it as an answer–