UPDATE-no-op in SQL MERGE statement

前端 未结 1 614
没有蜡笔的小新
没有蜡笔的小新 2021-02-12 09:52

I have a table with some persistent data in it. Now when I query it, I also have a pretty complex CTE which computes the values required for the result and I need to insert miss

1条回答
  •  青春惊慌失措
    2021-02-12 10:13

    You could declare a dummy variable and set its value in the WHEN MATCHED clause.

     DECLARE @dummy int;
     ...
     MERGE
     ...
     WHEN MATCHED THEN
       UPDATE SET @dummy = 0
     ...
    

    I believe it should be less expensive than the actual table update.

    0 讨论(0)
提交回复
热议问题