I have a table1 with columns as C1, C2, C3 and C4
All these columns stores bit value(true or false).
How to write a select query which uses the logical operations on these columns and gets me the final result?
Ex.:
Select ((C1 OR C2) AND (C3 OR C4)) AS FinalResult
from table1
Bitwise Operators are supported for bit
columns:
Select ((C1 | C2) & (C3 | C4)) AS FinalResult
from table1
When both operands are bit
, the result is going to be same as if logical operators were applied.
Just test to see if it is equal to 1 (true):
Select CASE WHEN (C1 = 1 OR C2 = 1) AND (C3 = 1 OR C4 = 1) THEN 1 ELSE 0 END AS FinalResult
from table1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.