473,395 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Selecting A Time Range

The problem i am faced with is having to select records from a large database, where one of the criteria is the records must have an event time before 11:00:00. I have already seperated the time from a date/time field and is in the format HH:MM:SS.

When i try to use basic syntax, it is rejected due to the colons used between the hours/mins/seconds.

Please point me in the right direction.

Many thanks
Jan 1 '07 #1
8 2196
NeoPa
32,556 Expert Mod 16PB
The problem i am faced with is having to select records from a large database, where one of the criteria is the records must have an event time before 11:00:00. I have already seperated the time from a date/time field and is in the format HH:MM:SS.

When i try to use basic syntax, it is rejected due to the colons used between the hours/mins/seconds.

Please point me in the right direction.

Many thanks
Your WHERE clause should look something like :
Expand|Select|Wrap|Line Numbers
  1. WHERE Format([YourDate],'HH:nn')<'11:00'
Jan 2 '07 #2
Killer42
8,435 Expert 8TB
The problem i am faced with is having to select records from a large database, where one of the criteria is the records must have an event time before 11:00:00. I have already seperated the time from a date/time field and is in the format HH:MM:SS.

When i try to use basic syntax, it is rejected due to the colons used between the hours/mins/seconds.
What is the data type of your time field? If it's Text, then you should be able to do something like
Expand|Select|Wrap|Line Numbers
  1. WHERE [YourTime] < '11:00:00'
If it's date/time, then... um... what about
Expand|Select|Wrap|Line Numbers
  1. WHERE [YourTime] < #11:00:00#
There are a couple of other things to consider:
  • Can you show us what "basic syntax" you have tried?
  • When you say you have "separated" the time value, are you referring to a query which reformats it on the fly? Or a new field you added to the table and copied the time-only values into? I am assuming the latter (new field), so anything I say here may be completely incorrect if that's not the case.
  • The code NeoPa provided will save you the extra storage required for the time-only field, by working directly on the values in the original date/time field. However, since you referred to a "large" database, it might incur a significant processing overhead. If the performance is acceptable (and you don't expect the database to grow very much), then you might as well remove the time-only field and save the disk space. Otherwise, try my technique on the time-only field and you should (fingers crossed...) see better performance...
Jan 2 '07 #3
NeoPa
32,556 Expert Mod 16PB
In this particular case
Expand|Select|Wrap|Line Numbers
  1. WHERE Hour([YourDate])<11
would also work.
See Killer's notes above, but I would think creating the extra field would negate any performance benefits associated with processing a field natively rather than calling functions.
Jan 2 '07 #4
Killer42
8,435 Expert 8TB
...See Killer's notes above, but I would think creating the extra field would negate any performance benefits associated with processing a field natively rather than calling functions.
Surely you jest, sir. 8P

Let's say there are 10 million records. We copy the time value to a new field, and just for fun, let's index it.

So now we want to find records with a particular time value - say, 11:00 AM. Using the new field, we simply hit the index and retrieve the matching records. Using the function, we retrieve every one of those 10,000,000 records, perform a function on each, then throw it away if it didn't match.

Sometimes a little redundancy can make a big impact. It depends on the data, of course.
Jan 2 '07 #5
NeoPa
32,556 Expert Mod 16PB
No Killer - I jest not.
Let us assume that the OP has 10,000,000 records and wants to take up the space of a separate index for this one task.
The time taken to create or repopulate an index (You're surely not assuming that this data MUST stay static) is not offset by the time taken to run the embedded function.
Apart from that, how would 'Hitting the Index' return the records you need. Have you run a separate query in advance to create the Date/time field with the date part missing? This creates even more time that needs to be saved before the process can produce a positive time save.
I can accept that there may be circumstances where this can produce an overall time saving, but not that they are likely to occur much, or that the extra complication of the maintenance of the data would be worth that time in any but the most extreme of circumstances (Yours for instance :)).
Jan 2 '07 #6
Killer42
8,435 Expert 8TB
No Killer - I jest not.
Let us assume that the OP has 10,000,000 records and wants to take up the space of a separate index for this one task.
The time taken to create or repopulate an index (You're surely not assuming that this data MUST stay static) is not offset by the time taken to run the embedded function.
Apart from that, how would 'Hitting the Index' return the records you need. Have you run a separate query in advance to create the Date/time field with the date part missing? This creates even more time that needs to be saved before the process can produce a positive time save.
I can accept that there may be circumstances where this can produce an overall time saving, but not that they are likely to occur much, or that the extra complication of the maintenance of the data would be worth that time in any but the most extreme of circumstances (Yours for instance :)).
Ah, so you're including the time taken to populate the new field, and so on.

Anyway, having been in similar situations, I've found it well worthwhile to add a redundant field and populate it (and index it). Granted the "overall" time might include hours of processing to initially populate the new field, and a slight impact on updates/adds, reducing each user query from hours to seconds is a worthy goal.

I don't agree at all with the need to offset the setup time to produce a "positive time save". Setup time doesn't necessarily directly affect the end-user. A query which takes an hour each time, most definitely does.
Jan 2 '07 #7
NeoPa
32,556 Expert Mod 16PB
Killer,
I know you have an extreme situation with your database but don't assume that's the same for everybody. Most of my work, for instance, doesn't require that much attention to performance details.
Not many Access users or designers have queries that run for that long - if they did they should be looking elsewhere.
Jan 2 '07 #8
Killer42
8,435 Expert 8TB
Killer,
I know you have an extreme situation with your database but don't assume that's the same for everybody. Most of my work, for instance, doesn't require that much attention to performance details.
Not many Access users or designers have queries that run for that long - if they did they should be looking elsewhere.
Fair enough, I suppose.
Jan 2 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Punky | last post by:
Hi all, I've gotten a long way with my application, but now it's generating an error to which I know no response. I hope any of you can (and will) help me. Below is the code. It's a simple piece...
1
by: Sunny K | last post by:
Hi, I am having a problem with aquery. Firstly here is a script to create the table and insert some sample data: CREATE TABLE . ( (17) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , ...
13
by: Tony | last post by:
Hi everyone, I am new to javascript (and new to programming). I want to have to drop down menus. One will ask use to select from one of the 50 states. The second one will be ask user to select a...
6
by: Spartanicus | last post by:
I'd like to know if it's possible to use js to step through and select a header in an HTML document, select it's content and all content below it. Context: I'm wondering if it's possible to use...
0
by: brent | last post by:
Hi there... I have a stateless Session Bean issuing a select for a BLOB column. This bean is using a CachedRowSet. It seems to work for all other columns types other than a BLOB. Selecting a...
8
by: Kari Lavikka | last post by:
Hi! I have to select a random row from a table where primary key isn't continuous (some rows have been deleted). Postgres just seems to do something strange with my method. -- -- Use the...
4
by: visu | last post by:
I need a solution to my problem. the problem is I ll have a button in page ... and when i click it .. content of a div tag has to be get selected (i.e what we normally do with mouse to...
2
by: movieking81 | last post by:
If someone could help me with this, that would be great. I need to select a number of records from an SQL table based on a date range, so I started with this select. <html> <code> resultssql =...
5
by: megahurtz | last post by:
I need to put together an SQL statement and I can't think of how to make it work properly. The scenario is that I have news items in a database that have a launch time and can optionally have an...
0
by: drfish | last post by:
Hi, I'm a complete novice when it comes to VB so need some help. I would like a macro that performs linear regression for different cell ranges each time it is run, depending on the number of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.