Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Update if exist and insert if it doesn't
Message
From
11/08/2001 16:20:07
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Update if exist and insert if it doesn't
Miscellaneous
Thread ID:
00542663
Message ID:
00542663
Views:
37
Is there a way to do this in one instruction :

update mytable set datafield=datavalue where keyfield=keyvalue
if @@rowcount=0
insert into mytable (keyfield, datafield) values (keyvalue, datavalue)

In other words : for a given key update a row and if it doesn't exist insert a row with that key/data
Next
Reply
Map
View

Click here to load this message in the networking platform