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

后端 未结 9 1304
慢半拍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:00

    This works as well and may be better when you have multiple columns that you want to check if they are different.

      MERGE @t2 a
    
      using @t1 b
    
      ON a.PK = b.PK
    
      WHEN MATCHED AND CHECKSUM(a.PK,a.VALUE)!= CHECKSUM(b.pk,b.VALUE)
    
      THEN UPDATE SET a.VALUE = b.VALUE;
    

提交回复
热议问题