Nulls and the MERGE statement: I need to set a value to infinity. How?

后端 未结 9 1306
慢半拍i
慢半拍i 2021-01-01 20:51

In SQL Server 2008, I\'m using MERGE. Everything is fine except that I have 2 nullable columns. If I pass a null value and the target isn\'t null, MERGE doesn\'t see a diffe

相关标签:
9条回答
  • 2021-01-01 21:13

    Actually, this works better. Just add another substitution value as an OR :-

    WHEN MATCHED AND 
        ( 
        NOT (IsNull(tgt.C, 0) = IsNull(src.C, 0)) OR NOT (IsNull(tgt.C, 1) = IsNull(src.C, 1)) 
        ) 
    THEN ....
    
    0 讨论(0)
  • 2021-01-01 21:16
    WHEN MATCHED AND
    (
       NULLIF(tgt.C, src.C) IS NOT NULL OR NULLIF(src.C, tgt.C) IS NOT NULL
    )
    THEN
    
    0 讨论(0)
  • 2021-01-01 21:18

    You can use

    WHEN MATCHED AND EXISTS (SELECT tgt.C EXCEPT SELECT src.C)
    

    See this article for more on this issue.

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