SQL Server insert if not exists best practice

The Solution to SQL Server insert if not exists best practice is


Semantically you are asking "insert Competitors where doesn't already exist":

INSERT Competitors (cName)
SELECT DISTINCT Name
FROM CompResults cr
WHERE
   NOT EXISTS (SELECT * FROM Competitors c
              WHERE cr.Name = c.cName)

~ Answered on 2011-03-13 09:21:10


Most Viewed Questions: