SQL: Can I negate a condition in a where clause?

后端 未结 5 804
栀梦
栀梦 2021-01-13 00:28

I want to check if a boolean is true, then decide in the WHERE clause what condition to use.

Say the boolean variable is @checkbool:

SELECT *
FROM Ta         


        
5条回答
  •  逝去的感伤
    2021-01-13 01:00

    select *
    from TableA A
    where
        (@checkbool = 1 and A.Id = 123) or
        (@checkbool = 0 and A.Id <> 123)
    

提交回复
热议问题