gbnorton
asked on
access query find closest date and time to the minute
I'm using three queries to match records on Date and Time to the minute. My current query works when there is an exact match
qry_Glassing returns a set of records that includes DateTime from table Glassing.
qry_Furnace formats the DateTime to the minute on table Furnace.
qry_Temp7 joins qry_Glassing and qry_Furnace on DateTime.
Here is my current query:
SELECT qry_Glassing.DateTime AS GlassingTime, qry_Glassing.Etch_Lot, qry_Glassing.PN, qry_Furnace.DateTime AS FurnaceTime, qry_Furnace.Temp7_AVE
FROM qry_Glassing INNER JOIN qry_Furnace ON qry_Glassing.DateTime = qry_Furnace.DateTime
ORDER BY qry_Furnace.DateTime;
DateTime format
[DateTime]
6/6/2013 12:07 PM
When there is not an exact match for each record, I need the next record that is closest to the minute:
Thanks,
Brooks
qry_Glassing returns a set of records that includes DateTime from table Glassing.
qry_Furnace formats the DateTime to the minute on table Furnace.
qry_Temp7 joins qry_Glassing and qry_Furnace on DateTime.
Here is my current query:
SELECT qry_Glassing.DateTime AS GlassingTime, qry_Glassing.Etch_Lot, qry_Glassing.PN, qry_Furnace.DateTime AS FurnaceTime, qry_Furnace.Temp7_AVE
FROM qry_Glassing INNER JOIN qry_Furnace ON qry_Glassing.DateTime = qry_Furnace.DateTime
ORDER BY qry_Furnace.DateTime;
DateTime format
[DateTime]
6/6/2013 12:07 PM
When there is not an exact match for each record, I need the next record that is closest to the minute:
Thanks,
Brooks
and formatted:
SELECT qry_Glassing.DateTime AS GlassingTime, qry_Glassing.Etch_Lot, qry_Glassing.PN, qry_Furnace.DateTime AS FurnaceTime, qry_Furnace.Temp7_AVE
FROM qry_Glassing INNER JOIN qry_Furnace ON qry_Glassing.DateTime = qry_Furnace.DateTime
where qry_Furnace.DateTime=(select max(DateTime) from qry_Furnace where qry_Furnace.DateTime<= qry_Glassing.DateTime)
ORDER BY qry_Furnace.DateTime;
also see if following would work:
SELECT qry_Glassing.DateTime AS GlassingTime, qry_Glassing.Etch_Lot, qry_Glassing.PN, qry_Furnace.DateTime AS FurnaceTime, qry_Furnace.Temp7_AVE
FROM qry_Glassing INNER JOIN qry_Furnace ON qry_Glassing.DateTime => qry_Furnace.DateTime
ORDER BY qry_Furnace.DateTime;
SELECT qry_Glassing.DateTime AS GlassingTime, qry_Glassing.Etch_Lot, qry_Glassing.PN, qry_Furnace.DateTime AS FurnaceTime, qry_Furnace.Temp7_AVE
FROM qry_Glassing INNER JOIN qry_Furnace ON qry_Glassing.DateTime => qry_Furnace.DateTime
ORDER BY qry_Furnace.DateTime;
ASKER
oleggold,
I tried your your suggestions with no joy. Further observation of our data showed that the next record we need would be within 3 minutes. So we wrote a routine to add 1, 2, or 3 minutes to the time. Thanks for giving it a go.
I tried your your suggestions with no joy. Further observation of our data showed that the next record we need would be within 3 minutes. So we wrote a routine to add 1, 2, or 3 minutes to the time. Thanks for giving it a go.
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for gbnorton's comment #a39562107
for the following reason:
Further observation of our data showed that the next record we need would be within 3 minutes. So we wrote a routine to add 1, 2, or 3 minutes to the time.
Accepted answer: 0 points for gbnorton's comment #a39562107
for the following reason:
Further observation of our data showed that the next record we need would be within 3 minutes. So we wrote a routine to add 1, 2, or 3 minutes to the time.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
mark_wills,
Your suggestion gets me very close. You last comment is accurate. There are multiple rows within minutes of each other. I'll post another question for that. I hope you'll take a look.
Thanks,
Brooks
Your suggestion gets me very close. You last comment is accurate. There are multiple rows within minutes of each other. I'll post another question for that. I hope you'll take a look.
Thanks,
Brooks
SELECT qry_Glassing.DateTime AS GlassingTime, qry_Glassing.Etch_Lot, qry_Glassing.PN, qry_Furnace.DateTime AS FurnaceTime, qry_Furnace.Temp7_AVE
FROM qry_Glassing INNER JOIN qry_Furnace ON qry_Glassing.DateTime = qry_Furnace.DateTime
where qry_Furnace.DateTime=(sele
ORDER BY qry_Furnace.DateTime;