Bitwise operations in MSAccess Query

  • Thread starter Thread starter Bart Steur
  • Start date Start date
B

Bart Steur

Hello,

I want to use a bitwise OR comparison in a MSAccess Query.

I've tried the following:

SELECT * FROM MyTable WHERE MyValue OR 2 <> MyValue.

The comparison returns always TRUE. Because the part 'MyValue OR 2' always
returns TRUE (-1). Then comparison TRUE <> MyValue is always TRUE also
(unless MyValue = -1 which is the numeric value of TRUE).

I expect one of the following:

1 OR 2 = 3 >>> False
2 OR 2 = 2 >>> True
3 OR 2 = 3 >>> True
4 OR 2 = 6 >>> False
5 OR 2 = 7 >>> False
6 OR 2 = 6 >>> True
Ect. Etc.

Please help.

Thanks,

Bart
 
Just build a custom function...as that will support bitwise operations.

So, you would now use:

SELECT * FROM MyTable WHERE MyOr([MyValue],2) = True



You then in a standard module simply go:


Public Function MyOr(p1 as varient, p2 as varient) as Boolean

MyOr = false

if isnull(p1) = true then
exit function
endif
if isnull(p2) = true then
exit function
endif

MyOr = ( clng(p1) or clng(p2) ) = clng(p1)

end Function

The above is complete air code...but you get the idea.

So, just send the values to a function that can do the bitwise stuff for
you. What your function does is really up to you....
 
The bitwise OR operator BOR is only available in 'ANSI' mode.
Unless your query or database is in 'ANSI' mode, you won't
be able to use it.

If you have one specific bit that you want to test, you can
construct a specific arithmetic expression to test it:

Where (((Myval\2) mod 2) = 1)

or more generally:
Where (((Myval\(2^b)) mod 2) = 1)

Otherwise you need to construct a VBA function to
do the arithmetic test.

(david)
 
U¿ytkownik "K.olma said:
Hello,

I want to use a bitwise OR comparison in a MSAccess Query.

I've tried the following:

SELECT * FROM MyTable WHERE MyValue OR 2 <> MyValue.

The comparison returns always TRUE. Because the part 'MyValue OR 2' always
returns TRUE (-1). Then comparison TRUE <> MyValue is always TRUE also
(unless MyValue = -1 which is the numeric value of TRUE).

I expect one of the following:

1 OR 2 = 3 >>> False
2 OR 2 = 2 >>> True
3 OR 2 = 3 >>> True
4 OR 2 = 6 >>> False
5 OR 2 = 7 >>> False
6 OR 2 = 6 >>> True
Ect. Etc.

Please help.

Thanks,

Bart
 
Back
Top