Can bitwise operators be employed in queries ? (1 Viewer)

john471

Registered User.
Local time
Tomorrow, 00:38
Joined
Sep 10, 2004
Messages
392
For (a relatively simple) example;

If I have a table tblBitMask with one field, BitMaskedField (number-byte data), that has 8 records:-

tblBitMask.BitMaskedField
1
2
3
4
5
6
7
8

I want to run a query e.g.
WHERE ((BitMaskedField AND 4) = true)
I would expect to return:-
4,5,6 & 7
(but not 8, as (8 AND 4) = false).

My attempts seem to return all records, no records, or only one record; none of which is the desired result (or I wouldn't have to post to the forum for help; would I ????)

On thinking about it further, I expect that what I am wanting to do violates normalisation rules, but it would give me maximum flexibility with minimum fields and records; so I am still wanting to know if it can be done.

Does anyone have any pointers ?

Thanx

John.
 

namliam

The Mailman - AWF VIP
Local time
Today, 14:38
Joined
Aug 11, 2003
Messages
11,696
what is this AND thing? I am not familiar with it.

As far as i know its a logical operotor....

Regards
 

john471

Registered User.
Local time
Tomorrow, 00:38
Joined
Sep 10, 2004
Messages
392
Don't Worry.

Ooops.

Should follow my own advice from time to time, and search before I post !!!

Found This Thread which had links to pages that answer my question.

Sorry to trouble you all.

John.
 

john471

Registered User.
Local time
Tomorrow, 00:38
Joined
Sep 10, 2004
Messages
392
http://support.microsoft.com/default.aspx?scid=kb;en-us;194206 said:
Jet drivers do not support bitwise operators
The Microsoft ODBC Driver for Access and the Microsoft OLE DB Provider for Jet do not provide support for bitwise operations in SQL statements. Attempts to use AND, OR, and XOR with numeric fields in a SQL statement return the result of a logical operation (true or false).

SELECT tblBitMask.BitMaskedField
FROM tblBitMask
WHERE (((bAnd([BitMaskedField],4))=True));

Public Function bAnd(ByRef lng1 As Long, ByRef lng2 As Long) As Boolean
bAnd = lng1 And lng2
End Function

Does the trick :)

namliam, the links off the thread that I posted a link to above may enlighten you on bitwise operators, if you are interested.
 

Users who are viewing this thread

Top Bottom