Solved

Query not working with number

Posted on 2006-11-30
5
160 Views
Last Modified: 2010-05-18
I'm trying to make a query that will select records

where category = restaurant, restaurant and bar, etc (see below)
AND
24hour = True

I had a previous recordset but instead of 24hour = True  best = true: which works fine (SQL below)

SELECT *
FROM entertainment
WHERE category in ('Restaurant' , 'Restaurant and Bar', 'Restaurant and Club', 'Restaurant, Bar and Club') AND best = True
ORDER BY ID DESC

When I change "best = true" to "24hour = true" I get error "Syntax error (missing opperator)" I assume this is becasue "24hour" starts with a number or some other small problem with my syntax. Below is what I have. Does anyone know what I'm din wrong?

SELECT *
FROM entertainment
WHERE category in ('Restaurant' , 'Restaurant and Bar', 'Restaurant and Club', 'Restaurant, Bar and Club') AND 24hour = True
ORDER BY ID DESC
0
Comment
Question by:elliottbenzle
[X]
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
  • 2
  • 2
5 Comments
 
LVL 25

Expert Comment

by:Rouchie
ID: 18044011
Not sure which database you're using, but SQL Server doesn't use True/False.  It uses a bit field instead which is 1/0
It obviously depends on how you designed the tables, but you should always use a bit field for true/false values, in which case your query becomes this:

SELECT *
FROM entertainment
WHERE
     (category in ('Restaurant' , 'Restaurant and Bar', 'Restaurant and Club', 'Restaurant, Bar and Club')) AND
     (24hour = 1)
ORDER BY ID DESC
0
 
LVL 4

Author Comment

by:elliottbenzle
ID: 18044813
Rouchie,

Thanks, I'm using an Access database. I fixed the problem by changing the name of the column from "24hour" to "twentyfourhour Any idea why the query won't work when it starts with a number?
0
 
LVL 25

Accepted Solution

by:
Rouchie earned 300 total points
ID: 18044846
Probably because Access automatically reads the start of the word (the numbers) and presumes it's a number, then throws an error.  24hour may even be the name of a built-in time function in access.  This is the most common cause of problems.

In SQL you can wrap braces around the column name to force it to read correctly:  

SELECT *
FROM entertainment
WHERE
     (category in ('Restaurant' , 'Restaurant and Bar', 'Restaurant and Club', 'Restaurant, Bar and Club')) AND
     ([24hour] = 1)
ORDER BY ID DESC
0
 
LVL 11

Assisted Solution

by:dodge20
dodge20 earned 200 total points
ID: 18045771
Actually I believe access uses -1,0 for yes/no fields.

-1 means yes
0 means no
0
 
LVL 11

Expert Comment

by:dodge20
ID: 18045870
My previous comment only applies if you have your acces field set to type yes/no. If it is a text field, you can ignore it.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

636 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