• the new 2008 booksonline has a lot of stuff on MERGE and EXCEPT

    http://technet.microsoft.com/en-us/library/bb510625.aspx

    the neat thing is how it has clauses for WHEN MATCHED and NOT MATCHED:, when the merge finds a match, based on the criteria, you know you need to update, if no match was found it must be new

    USE AdventureWorks;

    GO

    -- Create a temporary table variable to hold the output actions.

    DECLARE @SummaryOfChanges TABLE(Change VARCHAR(20));

    MERGE INTO Sales.SalesReason AS Target

    USING (VALUES ('Recommendation','Other'), ('Review', 'Marketing'), ('Internet', 'Promotion'))

    AS Source (NewName, NewReasonType)

    ON Target.Name = Source.NewName

    WHEN MATCHED THEN

    UPDATE SET ReasonType = Source.NewReasonType

    WHEN NOT MATCHED BY TARGET THEN

    INSERT (Name, ReasonType) VALUES (NewName, NewReasonType)

    OUTPUT $action INTO @SummaryOfChanges;

    -- Query the results of the table variable.

    SELECT Change, COUNT(*) AS CountPerChange

    FROM @SummaryOfChanges

    GROUP BY Change;

    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!