Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

"Through the Query of time"

Posted on 2000-02-24
5
Medium Priority
?
140 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 300 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

722 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