Home Forums SQL Server 2008 T-SQL (SS2K8) MERGE Statement DELETE from TARGET when not in SOURCE 'hanging' RE: MERGE Statement DELETE from TARGET when not in SOURCE 'hanging'

  • Apologies I probably didn't make my self clear, the query wasn't hanging but was taking an age to execute to the point i would stop the query.

    I think it was because it was trying to delete everything in my target table that didn't have a match to the source.

    After creating my target table using a CTE

    WITH k_target AS

    (

    SELECT *

    FROM Kart

    WHERE sessionid = @sessionid

    )

    MERGE k_target

    it worked but not as expected. It deleted everything that wasn't in my source for that sessionid. However the other records for that sessionid I want to keep as they are not of offer_type 'GWP'.