Results 1 to 2 of 2

Thread: Replace

  1. #1
    Join Date
    Feb 2002

    Unanswered: Replace

    I know there is a function in MySQL where you can use "Replace" to update a row if one already exists and if the row does not exist it will insert a new row. Can this be done in MSSQL also? Thanks

  2. #2
    Join Date
    Oct 2001
    if exists (select * from tbl where ...)
    update tbl set ...
    insert tbl ....

    update tbl set ...
    select @error = @@error, @rowcount = @@rowcount
    if @@error = 0 and @rowcount = 0
    insert tbl ....

    I include the @@error in the second method to show that if you check one then you will lose the other so have to save them both in one statement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts