Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Access SQL - Bit-wise and

Status
Not open for further replies.

snerting

Programmer
Oct 20, 2005
52
I have a bitfield in a database represented through a Long integer. I want to run sql to check if certain bits are set.

Example:
A field in the db is (64+32=96). I want to see if bit 5 is set.

Using regular VB6:
Debug.Print (96 AND 32)
32

However, using "WHERE 0 > (myBitField AND 32)" won't work as AND is reserved by SQL.

I tried using "&" but that ended up adding the integers.

How do you do this in MS Access SQL?
 
SQL does logical AND, VB does bitwise AND.
In a standard code module create the following function:
Code:
Public Function myAnd(Arg1, Arg2)
If Not IsNull(Arg1) And Not IsNull(Arg2) Then myAnd = (Val(Arg1) And Val(Arg2))
End Function
And now the criteria:
WHERE myAnd(myBitField,32)>0

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top