Solved

"Through the Query of time"

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Path  to current project in Delphi. 2 79
HTML text in the body of an email (delphi code) 12 116
Error E2158 compiling with Delphi XE10 Seattle 2 99
RESTRequest Parameter 4 30
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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