Home Forums SQL Server 2008 T-SQL (SS2K8) MERGE Statement MULTIPLE INSERT into different tables RE: MERGE Statement MULTIPLE INSERT into different tables

  • Problem:

    -> I'm checking if the record exist in Contact table or not. If it exist then I will insert into employee table else I will insert into contact table then employee table.

    Re-reading your question, I don't think MERGE is what you want. As I understand it, your logic should be really simple:

    IF NOT EXISTS (SELECT 1 FROM Contact WHERE SomeField = @SomeValue)

    BEGIN

    INSERT INTO Contact(fieldlist) VALUES (valuelist);

    END

    INSERT INTO Employee(fieldlist) VALUES (valuelist);