code-tutorial.com

The best resources for developers

What is the best implementation of MySQL for SQL Server 2005?

--try an update
update tablename 
set field1 = "new value",
    field2 = "different value",
    ...
where idfield = 7

--insert if failed
if @@rowcount = 0 and @@error = 0
    insert into tablename 
           ( idfield, field1, field2, ... )
    values ( 7, "value one", "another value", ... )
merge tablename as target
using (values ("new value", "different value"))
    as source (field1, field2)
    on target.idfield = 7
when matched then
    update
    set field1 = source.field1,
        field2 = source.field2,
        ...
when not matched then
    insert ( idfield, field1, field2, ... )
    values ( 7,  source.field1, source.field2, ... )

Tags: mysql sql-server sql-server-2005

Source: By Michael Stum as answer to the question

This code snippet was collected from stackoverflow, and is licensed under CC BY-SA 4.0


Related code-snippets: