• certainly possible.

    remember linked servers are slow, especially if you are joining the data together with local or other rmeote data.

    the reason is if you did something like this:

    SELECT * From myTable

    INNER JOIN MyLinkedServer.SandBox.dbo.AnotherTable myAlias

    ON MyTable.ID = MyAlias.ID

    WHERE myAlias.CustomerID = 12

    looks pretty simple, right? with a WHERE statement that specific, i'd expect very few rows, since how many rows have that specific customerID?

    the problem is behind the scenes, the entire contents of the linked server table MyLinkedServer.SandBox.dbo.AnotherTable gets copied over into tempDB, and then joined to the local table, and then that gets filtered like a normal query.

    so if the remote tables are MillionBillion row tables, you see a massive performance hit.

    to avoid things like that, you want to use a divide and conquer strategy to minimize the data being copied.

    using OPENQUERY for example,

    SELECT *

    INTO #tmp

    FROM OPENQUERY( [MyLinkedServer],'SET FMTONLY OFF; EXEC (''USE SandBox; SELECT * FROM dbo.AnotherTable WHERe CustmerID = 12'')')

    SELECT * From myTable

    INNER JOIN #tmp myAlias

    ON MyTable.ID = MyAlias.ID

    WHERE myAlias.CustomerID = 12

    in the above example, the linked server pre-filtered all the rows on it's server side, before passing the results....that's a smaller temp table, so it's quicker.

    the rest of the command barely changed.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!