• michael.petrone (9/1/2014)


    Here is the Question:

    I'm fine with declaring the table in the beginning.

    I want to check the temp table while selecting - first time through temp table will be empty.

    So I want to use the record on the select - But then Insert SSN into Temp Table.

    Next Record, I want to check temp table for SSN, if in temp table don't select.

    If not in temp table - store in temp table and use record.

    Looping

    No looping.

    insert into the temp table, select distinct rows from source.

    When done, select from temp table for output.

    (or use OUTPUT clause with INSERT)

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden