• one of the things that is going to make this slow is the linked server;

    the execution plan will end up copying the entire table over to tempdb, and THEN filter the data witht eh WHERE / do the joins;

    that's a lot of data over the wire that's not needed, most likely.

    switching to a divide-and-conquor plan, you can get just the data that matches form the linke dserver into a temp table, adn then join on that.

    something like this is my first guess, without any DDL to back it up.

    --get the minimal data over the wire possible by using EXECUTE AT

    INSERT INTO #temp

    EXECUTE ( 'SELECT

    c.DocType,c.Crtd_DateTime,c.VendId,c.user1,c.vendid

    FROM marlin_test.dbo.apdoc c

    WHERE c.DocType = ''VO''

    AND c.Crtd_DateTime > ''2012-01-01 00:00:00''

    AND c.VendId LIKE ''01%'';' ) AT NJACCOUNTING01;

    --data was already filtered at linked server, just join and distinct it.

    SELECT DISTINCT

    d.dlr_reference_num,

    d.dlr_key,

    a.app_dlr_fkey,

    CONVERT(VARCHAR(30), a.app_key)AS RapAPP,

    c.user1,

    c.vendid

    FROM #temp c

    INNER JOIN dbo.application a

    ON CONVERT(VARCHAR(30), a.app_key) = SUBSTRING(c.user1, 1, 6),

    dbo.dealer d

    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!