• Can you try this:

    SELECT column1,'99' [a],left(column2,2) , max(column3) [c], 'Yes' [d], 'Test' [e]

    ,ltrim(rtrim(column1))+ltrim(rtrim(left(column2,2))) as test

    INTO #pre1

    FROM table1

    WHERE column4 = 'Yes'

    GROUP BY column1, left(column2,2)

    SELECT DISTINCT ltrim(rtrim(column1))+ltrim(rtrim(left(column2,2))) as test

    INTO #pre2

    FROM table2

    SELECT p1.column1, p1.a, p1.b, p1.c, p1.d, p1.e

    FROM #pre1 p1

    WHERE NOT EXISTS(SELECT 1 FROM #pre2 p2 WHERE p2.test = p1.test)

    You may also try creating unique clustered index on #pre2 (test)

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]