Solved

"Through the Query of time"

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How can I open IE in olecontainer? 7 109
APK file name 7 64
Delphi XE10, MySQL Query 4 109
Dev Express grid collapse 2 35
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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now