Improve company productivity with a Business Account.Sign Up

x
?
Solved

correct sql statement

Posted on 2006-10-30
3
Medium Priority
?
461 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

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

602 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