Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Test for bit status in an Integer

Author  Topic 

CXXXV
Starting Member

12 Posts

Posted - 2009-07-31 : 16:00:41
I have a field called GROUPS(INT) that is storing the INT equivalent of a Binary.

What is the syntax to write SQL where clause to test if the 4 bit is True for instance?

This doesn't work in MSSQL:

SELECT * FROM members
WHERE (groups & 0x02) > 0

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-07-31 : 16:24:00
Seems pretty close, but that'll check the 2 bit no?
DECLARE @Table TABLE (Val INT)

INSERT @Table
SELECT 1
UNION ALL SELECT 2
UNION ALL SELECT 4
UNION ALL SELECT 6
UNION ALL SELECT 8
UNION ALL SELECT 12
UNION ALL SELECT 16
UNION ALL SELECT 32

SELECT *
FROM @Table
WHERE Val & 4 > 0

SELECT * FROM @Table
WHERE (Val & 0x04) > 0
Go to Top of Page
   

- Advertisement -