I am trying to insert / update a single row in a table, but all the examples are there for sets.
Can someone fix my syntax please:
MERGE member_topic ON mt_member = 0 AND mt_topic = 110 WHEN MATCHED THEN UPDATE SET mt_notes = 'test' WHEN NOT MATCHED THEN INSERT (mt_member, mt_topic, mt_notes) VALUES (0, 110, 'test')
The resolution of per marc_s is to convert one line to a subquery - this makes me think that the MERGE command is not really intended for single-line upserts.
MERGE member_topic USING (SELECT 0 mt_member, 110 mt_topic) as source ON member_topic.mt_member = source.mt_member AND member_topic.mt_topic = source.mt_topic WHEN MATCHED THEN UPDATE SET mt_notes = 'test' WHEN NOT MATCHED THEN INSERT (mt_member, mt_topic, mt_notes) VALUES (0, 110, 'test');
merge sql-server upsert
Jacob Mar 19 '10 at 17:57 2010-03-19 17:57
source share