Solved

"Through the Query of time"

Posted on 2000-02-24
5
139 Views
Last Modified: 2010-04-04
------Querys with time fields-------

Assume I have a table like this:

MYTABLE With fields: Code (Integer Type), Time1 and Time2 (of Type TTime)

and I want to do a query like this:

SELECT * FROM mytable
WHERE time1 <= 12:00:00

But the program returns:

"Token not found.
Token 12.
Line Number 2"

Well, as you may have noticed I want to know how to do queries in time fields.

I tried removing the spaces in te WHERE clause, like this:

WHERE time1<=12:00:00

but then it returns:

"Invalid use of keyword. Token: time1<=12. Line number 2"
0
Comment
Question by:chachote
[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 10

Accepted Solution

by:
Lischke earned 100 total points
ID: 2554588
You need to place the time into quotes:

SELECT * FROM mytable
WHERE time1 <= "12:00:00"

Ciao, Mike
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2554613
hi chachote,

it is allways better to use a param in your query like

SELECT * FROM mytable
WHERE time1 <= :TheTime

and using following code

query1.Close;
query1.ParmByName('TheTime').AsDateTime := StrToTime('12:00:00');
query1.Open;


meikl
0
 

Author Comment

by:chachote
ID: 2554771
To meikl:

I really pretend to do it with params, but need to try it with some data first.

When I tried params my query wouldn't return anything. So I decided trying with "raw" data first. I gues if this works then parametrized queries would  too.

Chache
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2554865
well, ok, chachote,

then your statement must look like

SELECT * FROM mytable
WHERE time1 <= Cast("12:00:00" AS TIME)

or (not so good solution)

SELECT * FROM mytable
WHERE CAST(time1 AS CHAR(10)) <= "12:00:00"

(not tested)

meikl
0
 

Author Comment

by:chachote
ID: 2555035
Thank you guys, your ideas were good, so I can keep going.

Chache
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses
Course of the Month6 days, 7 hours left to enroll

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