Home Forums SQL Server 2008 T-SQL (SS2K8) How to Insert/Upadte data based on exist in mathcin table, in single query RE: How to Insert/Upadte data based on exist in mathcin table, in single query

  • here is a very basic MERGE exampel that might help, and of course you should read up on it in your books and in SQL Books Online:

    MERGE INTO dbo.tableA AS Target

    USING(

    SELECT ITEM, DESCRIPTION FROM dbo.tableB

    ) AS source

    ON (target.ITEM = source.ITEM)

    WHEN NOT MATCHED BY TARGET THEN

    INSERT (ITEM, [DESCRIPTION])

    VALUES (ITEM, DESCRIPTION);

    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!