Question

I am working on doing some data transfers moving data from one database to another and I would like to do this without using to much memory on the computer that I am running this data transfer program on. Currently the program is ran every minute, but I want to alter this so that I am fetching data every hour. Ultimately, I want to change the following query so that I am not grabbing just the most value but that I am grabbing data that is from the past hour:

SELECT Data.[Date / Time],
       DATA.[Hot Strip Mill Total],
       Data.[Basic Oxygen Furnace Total],
       Data.[Electro-Arc Furnace Total],
       Data.[J-9 Shop Total],
       Data.[Levy Maintence Building Total],
       Data.[Ford Body Shop Total],
       Data.[Ford Chiller Building Total],
       Data.[Ford Dearborn W Plant Total],
       Data.[Ford Dearborn E Plant Total], 
       Data.[Ford Dearborn Balcony Total], 
       Data.[Ford Final Assembly Total],
       Data.[Ford Frame Plant Total], 
       Data.[Ford Dearborn N Plant Total],
       Data.[Ford Tool and Die Total], 
       Data.[Ford Paint Plant Total],
       Data.[Ford Glass Plant Total], 
       DATA.[Hot Strip Mill Rate], 
       Data.[Basic Oxygen Furnace Rate], 
       Data.[Electro-Arc Furnace Rate],
       Data.[J-9 Shop Rate],
       Data.[Levy Maintence Building Rate],
       Data.[Ford Body Shop Rate],
       Data.[Ford Chiller Building Rate],
       Data.[Ford Dearborn W Plant Rate],
       Data.[Ford Dearborn E Plant Rate],
       Data.[Ford Dearborn Balcony Rate],
       Data.[Ford Final Assembly Rate],
       Data.[Ford Frame Plant Rate],
       Data.[Ford Dearborn N Plant Rate],
       Data.[Ford Tool and Die Rate],
       Data.[Ford Paint Plant Rate],
       Data.[Ford Glass Plant Rate]
       FROM DATA  
       WHERE Format(Data.[Date / Time], 'mm/dd/yyyy hh:nn:ss') >=
           (select Format(max(Data.[Date / Time]),'mm/dd/yyyy hh:nn:ss') from Data);

As in, it is now 10:51:00AM, my program is now running it would return data from greater than 09:51:00AM until now, Likewise at 11:51:00AM, return data from greater than 10:51:00 until 11:51:00AM. I am not that famililar with Access but I am fairly capable with queries. This one just has me lost. Can anyone help understand how accomplish this? Thanks

Was it helpful?

Solution

Since 1 day = 1, therefore 1 hour = 1/24. So -just for fun - you could even express your condition as

WHERE Data.[Date / Time] >= (Now()-1/24)

OTHER TIPS

If the data type of your Data.[Date / Time] is Date/Time, you don't need to apply Format() when using the values in a date-based comparison.

WHERE Data.[Date / Time] >= DateAdd("h",-1, Now())

That approach could be much faster than using Format() with every row of the table, especially if the [Date / Time] field is indexed.

I'm not sure what you meant with this sentence:

"Likewise at 11:51:00AM, return data from greater than 10:51:00 until 11:51:00AM."

If that means at 11:51:00 AM your Data table may include rows which have [Date / Time] values later than 11:51:00 AM, you can add another condition to the WHERE clause to exclude them.

WHERE Data.[Date / Time] >= DateAdd("h",-1, Now()) AND Data.[Date / Time] < Now()
WHERE Format(Data.[Date / Time], 'mm/dd/yyyy hh:nn:ss') >= DateAdd("h",-2, Now())
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top