我是T-SQL命令的新手,MERGE所以我在SQL逻辑中找到了一个可以使用它并想要对其进行测试的地方,但无法弄清楚我应该如何使用它:
MERGE
IF (EXISTS (SELECT 1 FROM commissions_history WHERE request = @requestID)) UPDATE commissions_history SET amount = @amount WHERE request = @requestID ELSE INSERT INTO commissions_history (amount) VALUES @amount)
请提出正确的用法。谢谢!
您在帮助中了吗?这是一个简单的例子:
MERGE dbo.commissions_history AS target USING (SELECT @amount, @requestID) AS source (amount, request) ON (target.request = source.request) WHEN MATCHED THEN UPDATE SET amount = source.amount WHEN NOT MATCHED THEN INSERT (request, amount) VALUES (source.request, source.amount);