T-SQL XOR Operator

后端 未结 9 650
既然无缘
既然无缘 2020-11-30 23:43

Is there an XOR operator or equivalent function in SQL Server (T-SQL)?

9条回答
  •  暖寄归人
    2020-12-01 00:33

    How about this?

    (A=1 OR B=1 OR C=1) 
    AND NOT (A=1 AND B=1 AND C=1)
    

    And if A, B and C can have null values you would need the following:

    (A=1 OR B=1 OR C=1) 
    AND NOT ( (A=1 AND A is not null) AND (B=1 AND B is not null) AND (C=1 AND C is not null) )
    

    This is scalable to larger number of fields and hence more applicable.

提交回复
热议问题