You didn't post and sample data or expectged results. But, if I'm understanding yo correctly you are trying to use a bit mask. Maybe this will help:DECLARE @Foo AS TABLE (Val BIGINT)INSERT @Foo (Val)VALUES(0), (1),(2), -- Second Right(64), -- Sixth Right(66), -- Second And Sixth Right(1569918) -- also Second And Sixth RightSELECT Val, Val & POWER(2, 1) AS SecondRight, Val & POWER(2, 6) AS SixthRight, CASE WHEN Val & POWER(2, 1) > 0 AND Val & POWER(2, 6) > 0 THEN 1 ELSE 0 END AS IsSecondAndSixthFROm @Foo