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

SQL condition

Status
Not open for further replies.

lizray

Programmer
Joined
May 14, 2008
Messages
126
Location
AU
I have constructed a Query in Access based on a table which contains the field STATUS ( a byte Variable). How do I specify the condition of bit 1 being set.I know little of SQL and under the field STATUS, I have tried
AND 1
and many variations as the criteria, with no Joy !!
 
post your query and an explanation of what you want returned.
 
G'day lizray,

From "under the field STATUS..." it sounds like you're using the query builder. If that's the case simply type the word "True" into that where condition box....

Good luck,

JB
 
in its simplest form, the query is :

SELECT People.Status
FROM People
WHERE (("AND 1"<>0));

I need to extract the people who have a "1" in the bit 0 of their status word
 
SELECT People.*
FROM People
WHERE people.status=1;

Good Luck,

JB
 
There are many bits in the status byte, with different purposes and in this case I only want those with Bit 0 set, so I need to use the AND operator
 
what is the data type of the field "status"? if its an integer of size byte then it must contain values between 0 and 255? And you're after the values 1, 3, 5, 7, etc?

Or is it text storing values such as 11011001, 11110111, 00001011 etc?

or am I completly misssing your point?
 
Perhaps this ?
SELECT *
FROM People
WHERE (Status And 1)=1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV..it almost works. the (status And 1) works but produces a result of -1 when I had expected it to be 1, whenever "status" had bit 0=1. Anu Ideas ??
 
OK, in SQL, And is a logical operator, not bitwise.
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 SQL code:
SELECT *
FROM People
WHERE myAnd(Status,1)=1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top