bitwise operator in SQL

I

Ivar

Hi All

I have a Table, In the table I have a field DataType Long Integer.
I want to determine if a value in this field is true or false using the AND
bitwise operator using SQL Query
Something Like:
SELECT TblName.Reference, TblName.BitFlags, (TblName.BitFlags And 512) AS
Expr1
FROM TblName;

The query runs but Expr1 is always true except when TblName.BitFlags is 0.
I'm assuming that if TblName.BitFlags <> 0 then that's true, if the number
<> 0 then that's true so Expr1 is also true
Can SQL handle what I'm asking it to do? If so then How Please :)

Thanks

Ivar
 
D

Douglas J Steele

Fascinating: I've never noticed that before, but I just tested and got the
same results as you!

Fairly easy to get around, though. Create a function along the lines of:

Function BitWise(Value1 As Long, Value2 As Long) As Boolean
BitWise = (Value1 And Value2)
End Function

then change your SQL to

SELECT TblName.Reference, TblName.BitFlags, BitWise(TblName.BitFlags, 512)
AS Expr1
FROM TblName;



"Ivar" wrote in message
Hi All

I have a Table, In the table I have a field DataType Long Integer.
I want to determine if a value in this field is true or false using the AND
bitwise operator using SQL Query
Something Like:
SELECT TblName.Reference, TblName.BitFlags, (TblName.BitFlags And 512) AS
Expr1
FROM TblName;

The query runs but Expr1 is always true except when TblName.BitFlags is 0.
I'm assuming that if TblName.BitFlags <> 0 then that's true, if the number
<> 0 then that's true so Expr1 is also true
Can SQL handle what I'm asking it to do? If so then How Please :)

Thanks

Ivar
 
I

Ivar

Thanks Doug for the idea
I am using something similar already.
I'm Passing A String to DAO to query the database table from outside Access.
I was hoping This could be done using SQL only
Thank you for the reply
Ivar
 
D

Douglas J Steele

Unfortunately, I think you're out of luck, then. You can't call user-defined
functions when running SQL from outside Access.

"Ivar" wrote in message
Thanks Doug for the idea
I am using something similar already.
I'm Passing A String to DAO to query the database table from outside Access.
I was hoping This could be done using SQL only
Thank you for the reply
Ivar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top