Solved

"Through the Query of time"

Posted on 2000-02-24
5
138 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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