Should I use != or <> for not equal in T-SQL?

前端 未结 14 1895
失恋的感觉
失恋的感觉 2020-11-22 04:23

I have seen SQL that uses both != and <> for not equal. What is the preferred syntax and why?

14条回答
  •  爱一瞬间的悲伤
    2020-11-22 04:55

    One alternative would be to use the NULLIF operator other than <> or != which returns NULL if the two arguments are equal NULLIF in Microsoft Docs. So I believe WHERE clause can be modified for <> and != as follows:

    NULLIF(arg1, arg2) IS NOT NULL
    

    As I found that, using <> and != doesn't work for date in some cases. Hence using the above expression does the needful.

提交回复
热议问题