0

I have an SQL insert in SQL-Server that looks like this:

  INSERT INTO Configuration.Localization ( languageid, localizationkey, localizationvalue)  VALUES
(lang,'core.common.altered','(altered)'),
(lang,'core.common.cancel','Cancel'),
(lang,'core.common.ordernumber','Order number'),
(lang,'core.common.prefix','Prefix') ...

and so on.

How do I modify this query to use UPDATE instead of insert (similarly to "ON DUPLICATE KEY UPDATE" in MySQL), while keeping the overall structure of the query (I want it still to be one operator, not many).

Preferably I would like to be specific in the query, that UPDATE must happen if lang and localizationkey both match.

ypercubeᵀᴹ
  • 113,259
  • 19
  • 174
  • 235
onkami
  • 8,791
  • 17
  • 90
  • 176
  • 1
    did you try using merge http://msdn.microsoft.com/en-us/library/bb510625.aspx – Recursive Oct 08 '14 at 08:54
  • I'd use the [solution by Aaron Bertrand](http://stackoverflow.com/questions/108403/solutions-for-insert-or-update-on-sql-server/21209295#21209295) – ypercubeᵀᴹ Oct 08 '14 at 09:32
  • I was about to post on the question when it was closed. http://craftydba.com/wp-content/uploads/2012/05/move-to-history.sql_.txt has code for an UPSERT. It happens to fall into on of the cases Aaron mentions. – CRAFTY DBA Oct 08 '14 at 09:40

0 Answers0