Office User said:
I need to find gaps in a series of time periods (ie 8-8:30am or
10-11:00am).
I have a table with the Time Periods listed as well as a query with each
workers date and times for each month. The Unmatched Query won't work
because one day the worker may be "clocked out" from 8-8:30 but another
day
may be "clocked out" from 10-11:00.
Here's the SQL of the Unmatched Query I attempted (in case it helps with
field names, etc)
SELECT [Time Periods].Period, [Time Periods].[Start Time]
FROM [Time Periods] LEFT JOIN [Grouped by Date & Time] ON [Time
Periods].[Start Time] = [Grouped by Date & Time].Login
WHERE ((([Grouped by Date & Time].Login) Is Null));
Any insight would be greatly appreciated.
Marcia
Well...you said "*any* insight"....
There are so many ways someone might model
time periods, so please start with describing the
original table that fuels the "query with each workers
date and times for each month." Please give the table
name(s), field names and types, plus some sample
data (which may be bogus, but illustrates what a
"gap" is). Then, please provide the SQL for this
preliminary query ([Grouped by Date & Time])
and results for your sample data.
Then, please present the results you expect from
your unmatched query using your sample data....
make sure your sample data illustrates how "clocked
out" at different times (that caused your unmatched
query not to "work") should work...
{BTW, it is never a good idea to include any punctuation
in an object name, especially a char that is also an operator
like "&". Also, somewhere down the line you may realize
that using spaces in your names just makes bracketing a
pain in the petui and does not really make your model any
more "readable." For example, "GrpByDateTime" would
be a start (although it hardly tells someone what the query
does).}
So...why is the modeling important?
A) A date/time field serves best as a point in time.
B) Elapsed time (gap/period) typically works best as a scalar
(i.e., Long or Integer) where you work with a unit of time
(like number of seconds).
For example, you might have "modeled" your Login as
a Date/Time (which makes sense to me...you are storing
a point in time). Whether you store the date *and the time*
or just the time (so date part will be 12/30/1899), the time
portion will be a fraction of 24 hours and computers have
trouble "matching" fractions (as in equalities of JOINs or
WHERE clauses).
It *might* be that your query simply fails in that respect,
and could be corrected by changing the ON clause to
something like
ON
Format([StartTime],"hh:nn:ss AMPM")
= Format([LogIn],"hh:nn:ss AMPM")
or, if fields contain date as well....
ON
Format([StartTime],"mm\-dd\-yyyy hh:nn:ss AMPM")
= Format([LogIn],"mm\-dd\-yyyy hh:nn:ss AMPM")
I'm assuming that table Time Periods was an
enumeration of all possible Start Time's. If so,
it would be easy enough to add one more field
(say "strStartTime"), run an update query that
fills in this field...
UPDATE
[Time Periods]
SET strStartTime =
Format([StartTime],"hh:nn:ss AMPM");
or (if need date as well)
UPDATE
[Time Periods]
SET strStartTime =
Format([StartTime],"mm\-dd\-yyyy hh:nn:ss AMPM");
then, in your "GrpByDateTime" compute
an extra field for a string LogIn (say "strLogIn")
Field: strLogIn: Format([LogIn],"hh:nn:ss AMPM")
Table:
Sort:
Show: <checked>
Criteria:
Or:
then, your unmatched query would join on
the 2 string fields....
===============================
another possible way would depend on how
your [Login] is determined...
if a login is always entered in specific increments of the
hour, i.e., 8:00, 8:15, 8:30, 8:45, 9:00, 9:15,...
then, you can compute the "number of increments"
since midnight for each Login....
then you probably would not even need your enumerated
table (if that is what [Time Periods] is)....
here is where I usually give a solution that typically
ends up having nothing to do with your problem...
so, it would be better if you first reply with requested
info from above...