Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Linked Server : Create, Populate & reuse a remote tmp table

$
0
0

Hello,

Here's the plan :

  • Perform a Select Query (1) on remote database via linked server
  • Store results of the Select, into a temporary table (1)
  • Perform another Select Query (2) on same remote database via linked server
  • Store results of the Select, into a temporary table (2)
  • Perform a Select on remote temp table (1) joined to remote temp table (2) via linked server.

Now I can successfully perform all of this thus:

  Select <columns> into [linkedServer].#Temp1 from [linkedServer].[database].[schema],[table1]
  Select <columns> into [linkedServer].#Temp2 from [linkedServer].[database].[schema],[table2]
  select <columns> from [linkedServer].#Temp1 join [linkedServer].#Temp2

.. but performance is terrible.

So doing some reading, I am led to believe that if I use OPENQUERY, or EXEC(string) AT  LinkedServer ... then things should whizz.

So, I made a 'Select Into #Temp'  statement and ran as :exec (@SQLString) AT LinkedServer;
And whilst this executed error free, I could not find the temp table afterwards.
At the moment, I am under the impression that after the exec statement, the session with the remote server ends and thus the temp table is dropped !?

Can anyone firstly verify  the above logic ?
Secondly, assuming the connection is the issue, is there a way to do what I am trying to do ?  i.e. persist the connection so that I may re-use my temp table ?

I realize I could go down the gobal temp table route ... but I'd like to avoid if at all possible .

many thanks for anyone who can help clarify things !!


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>