0

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
0

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 Assumes the columns aren't nullable though. 1 | NULL is NULL whereas TRUE or UNKNOWN would be TRUE
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.