Merge STMT

  • Does SQLServer have a merge stmt that is similiar to Oracle merge? I am needing to do an insert or update if the data is not there.  Any ideas?

  • Just wrap an update and insert in 1 transaction:

    Begin Transaction

    Update YourTable

    Set  Column(s) = OtherTable.Columns

    From YourTable

    Inner Join OtherTable

      On (YourTable.KeyColumn(s) = OtherTable.KeyColumns(s))

    Insert Into YourTable

    Select ....

    From OtherTable

    Where Not Exists (

       Select * from YourTable

       Where YourTable.KeyColumn(s) = OtherTable.Columns

    )

    Commit

  • Thank you

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply