• Luis Cazares (7/28/2014)


    --When there is a row in Grantors but not in the tempTable, delete the Grantors row

    WHEN NOT MATCHED BY Source AND Target.EntryNumber = @PassedInEntryNumber THEN

    DELETE;

    DELETE g

    FROM #Grantors g

    WHERE EXISTS( SELECT *

    FROM #tempTors t

    WHERE g.EntryNumber = t.EntryNumber

    AND g.Sequence <> t.Sequence)

    Your suggestion got me thinking about the problem a bit more. When I looked at your comment about needing additional criteria, it dawned on me that this will only execute for 1 entry number that is in the temp table. (Data entry stuff). By adding the @PassedInEntryNumber to the NOT MATCHED BY Source CLAUSE it was able to add that extra dimension to do the delete properly.

    Thanks for the help.

    __________________________________________________________________________________________________________
    How to Post to get the most: http://www.sqlservercentral.com/articles/Best+Practices/61537/