Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a tinyint column that represents a set of flags. Assuming I wanted to know if a specific bit was set or not, how can I do bitwise AND/OR in a stored procedure?

share|improve this question
up vote 3 down vote accepted

From your previous questions you use SQL Server. So you can use the & operator.

e.g. to see if the bit for 4 is on (and assuming NULL should return NULL)

SELECT CASE number & 4 WHEN 4 THEN 1 WHEN 0 THEN 0 END
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.