views:

53

answers:

1

is it possible to execute a query that inserts the Row if the ID don't exist and Update the Row if the ID already exists in a single sql statment?
i mean not using stored procudures just plain SQL.
i already doing LoadRecord and if noone returned then insert and if any record is returned then update.
but i wanted to know if there is any way to do it without hitting on the DB server Twice.
The ID field is an integer Primary Key that is not an auto incriment.
thanks

+6  A: 

Have a look at

astander
yup -the new MERGE command in SQL Server 2008 is exactly what fits the bill
marc_s