correct sql statement

Posted on 2006-10-30
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"
Question by:al4629740
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 20

Assisted Solution

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

Expert Comment

ID: 17835264
The query should be like this:

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

Accepted Solution

smidgie82 earned 400 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.


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

726 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