Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Deciphering bitwise flags

$
0
0

I read the article below and believe it to be a good fit for what I'm trying to do.  I'm having a little trouble interpreting how it applies to my situation.

http://sqlmag.com/t-sql/get-wise-about-bits

I'm trying to understand what the where clause should look like below.  Let's say the CategoriesFlag value for a record is 6.  It should return orders for orders of category B, category C, or categories B and C.

CREATE TABLE #client (ClientID INT,
				  ClientName VARCHAR(100),
				  IsCategoryAClient BIT,
				  IsCategoryBClient BIT,
				  IsCategoryCClient BIT)

CREATE TABLE #order (OrderID INT,
				 ClientID INT,
				 OrderDate DATETIME,
				 CategoriesFlag TINYINT)

-- Category definitions
-- 1 - Category A
-- 2 - Category B
-- 4 - Category C

-- therefore a CategoriesFlag value of 6 would mean that the client is a category B and category C client, but not a category A client

SELECT c.ClientName, o.OrderID
  FROM #client AS c JOIN #order AS o ON c.ClientID = o.ClientID
  WHERE -- some expression that restricts results to only category B OR category C clients

Can someone help me out with the where clause here using the & and | operators?

Thanks!




Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>