Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

correct sql statement

Posted on 2006-10-30
3
Medium Priority
?
459 Views
Last Modified: 2011-08-18
I am trying to select all records from a column in Microsoft Access.  The column is checkbox column with Yes/No as the data type.  Is this the correct way to query a checked box in Access using sql statements?

        esql = "Select * from " & c & " Where Rearrested = 1"
0
Comment
Question by:al4629740
3 Comments
 
LVL 20

Assisted Solution

by:hes
hes earned 400 total points
ID: 17835235
Just for readability I like to use
esql = "Select * from " & c & " Where Rearrested =" & vbTrue
0
 
LVL 5

Expert Comment

by:daohailam
ID: 17835264
The query should be like this:

SELECT <columns|*> FROM <table> WHERE <column> = <smth> ...
0
 
LVL 9

Accepted Solution

by:
smidgie82 earned 1600 total points
ID: 17835272
Hi hes,

My experience (with access 2003) is that yes/no fields will compare correctly against TRUE and FALSE, but not 1 and 0.  So, to work correctly, change your query to
esql = "SELECT * FROM " & c & "WHERE Rearrested = TRUE".

If you're doing it from VBA, this is equivalent to hes's solution.  But this method will also work if, say, used from Java via JDBC.  Or Access's builtin SQL editor.

Cheers!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This video teaches viewers about errors in exception handling.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question