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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bitwise logical comparison in SQL statement 1

Status
Not open for further replies.

mlittman

Technical User
Nov 27, 2001
3
US
I have a series of questions, each with 8 possible "yes/no" choices. The answers are not mutually exclusive (ie, one can select none, 1, 2,... all 8 of the responses). To save space, I have encoded each question's answer as an integer from 0-255, based upon the "on/off" state of each of the 8 bits for the question. I am building an SQL statement which will retrieve records in which a specified bit is matched, however the bitwise comparison is not working properly within Access SQL. This syntax seems like it should work, but does not:

SELECT vol_last, vol_first FROM tblVol WHERE vol_act = True AND ((vol_qB And 15) = 15)

Are bitwise logical comparisons supported in SQL? Or it is time to implement another approach, such as retrieving an initial recordset, and travelling through it making the comparison in code?
Thanks for thoughts!!
 
I suspect that this
[blue][tt]
... vol_qB And 15 ...
[/tt][/blue]
is being treated as a Boolean operation equivalent to
[blue][tt]
vol_qb <> 0 AND 15 <> 0
[/tt][/blue]
If you want bitwise operations then write a public function in a module
[blue][tt]
Public Function BitAnd( Arg1 As Integer, Arg2 As Interer ) As Integer
BitAnd = Arg1 AND Arg2
End Function
[/tt][/blue]
then
[blue][tt]
SELECT vol_last, vol_first FROM tblVol
WHERE vol_act = True AND BitAnd(vol_qB, 15) = 15
[/tt][/blue]
 
To save space
They used to do that years ago when I was a boy. Now you can buy a disc drive that can balance on your thumb nail and go down your local store and get a 250 Megabyte flash memory key.

They also did it on Apollo missions as the computers were about the same size as the one that runs your keyboard.

So basically don't try and code information. Leave it as explicit as possible. That's a key of the relational approach. SQL was designed for end users. End users don't do things like AND their thirst with a coffee machine. The buy a drink.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top