我正在嘗試在表上執行單行插入/更新操作,但所有示例均爲集合。單行MERGE/upsert SQL Server中的語法
任何人都可以解決我的語法請:每marc_s
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')
分辨率是單列轉換爲子查詢 - 這讓我想起了MERGE命令是不是真的打算單列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');
嗯,我的瀏覽器中這些行間隔如此接近,以至於某些下劃線未顯示。 – Jacob 2010-03-19 17:58:13