RE: Find missing Working Days
- From: Dale Fye <dale.fye@xxxxxxxxxx>
- Date: Fri, 18 Apr 2008 04:55:01 -0700
I keep a table (tbl_Numbers) handy for this kind of thing. It generally
contains one field (intNumbers) and the values of 0 through 9.
I then create a query (qryNumbers) that generates numbers from zero through
999 (you can easily change this to make the range 9999).
SELECT hundreds.intNumber * 100 +
Tens.intNumber * 10 +
Ones.intNumber as intNumber
FROM tbl_Numbers as Hundreds,
tbl_Numbers as Tens,
tbl_Numbers as Ones
To do what you are looking for, I would do something like the following.
The subquery generates a list of sequential dates between two dates you
provide (you can hard code these or use a parameter query). The rest just
joins this set of sequential dates to your table on the date column (using a
left join). The WHERE clause identifies the missing dates and whether the
day of the week is M - F:
SELECT M.SeqDates AS MissingDate
FROM (Select DateAdd("d", [intNumber], #4/1/08#) as SeqDates
FROM qry_Numbers
WHERE DateAdd("d", [intNumber], #4/1/08#) < #4/30/08#) AS M
LEFT JOIN tbl_SomeDates AS T ON M.SeqDates = T.SomeDate
WHERE T.SomeDate IS NULL
AND DatePart("w", M.SeqDates, 2) < 6
ORDER BY M.SeqDates
HTH
Dale
--
Don''t forget to rate the post if it was helpful!
email address is invalid
Please reply to newsgroup only.
"Evi" wrote:
My database needs a record entering for every working day. A working day is.
defined as every day from Monday to Friday. This includes Bank Holidays and
other holidays, so at least that bit isn't a problem
Can anyone think of a query that can check if any days are missing? eg one
week I didn't enter a record for Tuesday? I suspect the answer will have
something to do with DatePart but I can't figure out how to find the missing
numbers. ie the
I suppose that I could cycle through the record with VBA and print the
results into a table if a number from 1 to 5 is out of sequence but I wonder
if it could be done with a query.
It wouldn't matter if the query also returned the results for the week I ran
it, if the query was run half way through the week.
The datefield is called WkDate in TblWorkRecord.
Evi
- Follow-Ups:
- Re: Find missing Working Days
- From: Evi
- Re: Find missing Working Days
- References:
- Find missing Working Days
- From: Evi
- Find missing Working Days
- Prev by Date: Re: Table not available for Append query
- Next by Date: Re: Queries not returing all results
- Previous by thread: Find missing Working Days
- Next by thread: Re: Find missing Working Days
- Index(es):
Relevant Pages
|