A
A
Alexey Vladimirov2014-02-12 12:11:54
SQL
Alexey Vladimirov, 2014-02-12 12:11:54

How to perform a join on the linked server side?

Hello gentlemen.
It is necessary to join two tables, and one of them is located on a different server.
Sample example:

SELECT c.id AS card_id
, cmo.SaleID AS sale_user_name
, c.vin
FROM  dbo.Cards AS c 
INNER JOIN SQL11.Clients.dbo.cmOrders AS cmo 
ON cmo.VIN = c.vin
       WHERE(cmo.id =(SELECT MAX(id) 
        FROM SQL11.Clients.dbo.cmOrders AS cmo2
          WHERE      (VIN = c.vin)))

Yes, such a crooked query...
I heard somewhere that in such queries you can explicitly specify on which side to execute the join. In this case, it is necessary that it be on the 11th server, because the table is very large, and it makes no sense to drive it back and forth once again.
Are there any thoughts?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Isaev, 2014-02-12
@xvladimirov

use REMOTE in INNER JOIN
technet.microsoft.com/en-us/library/ms173815.aspx

I
Igor, 2014-08-09
@rze

Or through f-yu OPERNROWSET.

SELECT f.* FROM OPENROWSET( 'SQLNCLI', ' Server='Server.domain.local; Trusted_Connection=yes;,
     'SELECT column1, column2 FROM remotedb.schemaname.tablename WHERE column1 IS NOT NULL

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question