How to compare different values in sql server

前端 未结 4 1189
日久生厌
日久生厌 2021-01-07 08:10

I must to check if two values, X and Y are different. If both are null, they must be considered as equal.

The unique way I found is:

select 1 as valu         


        
4条回答
  •  南方客
    南方客 (楼主)
    2021-01-07 08:31

    I think you could use COALESCE for that

    WHERE coalesce(@X, '') <> coalesce(@Y, '')
    

    What it does it returns an empty string if one of variables is null, so if two variables are null the two empty strings become equal.

提交回复
热议问题