Re: Create Weekly and Monthly Flag in database/table
- From: Bob Quintal <rquintal@xxxxxxxxxxxxx>
- Date: 30 Aug 2007 21:12:19 GMT
"Lucas_london via AccessMonster.com" <u35944@uwe> wrote in
7779dded54462@uwe:">news:7779dded54462@uwe:
Bob Quintal wrote:-
------------------------------------------------------------------Hi Bob,[quoted text clipped - 38 lines]
FROM Data
WHERE field1 In ('LLOY','RSA');
the weekday(datefield [,optional first day of week)) returns a
number which represents the day of the week, Without the optional
number, fridays are 6.
In the query designer if you put your field2, then surround it wth
the weekday function, you can set the 6 in the criteria row.
Access will add a label, in the form of expr1:, you can change
that to any name you want for the column (within reason)
Now the issue with the missing fridays, one approach is to make a
small table with the holidays that fall on a friday. and join that
table on the dates, changing the join to show all records from
your main table ano the ones from the holidays table where the
dates are equal.
now you can add one to the weekday if the holiday table date is
not null.
so your query becomes something close to
SELECT *
From DataLEFT Join Holidays
ON data.field2 = Holidays.holiday
WHERE field1 In ('LLOY','RSA');
AND weekday(field2)
+ iif( isnull(Holidays.holiday),0,1)
= 6;
Q
[quoted text clipped - 18 lines]Hi
instructions on how to write the query you need. Please supply a
few more details.
----------- ------the dateadd() function will point you in the right direction
Hi Bob,
Thanks very much for the code and explaining how it works. As per
my orginal posting, I also need to devise a similar query to bring
back monthly data - is there a similar function I could use for
this? I've checked the functions available in Access but could not
see one. Again, just likely the weekly query, for each month I
want to bring back the row for the last available date in that
month. I suspect I will need to use a combination of functions to
get the result I need but maybe I'm over complicating things. Any
ideas on the best approach?
Many Thanks,
Lucas
if you subtract 1 from the first of any month, you get the last day
of the previous month. The dateserial builds a date from numbers.
The trick is to get the month numbers, from somewhere, perhaps a
small table with the first of each month, or the numbers 1to 12
LastOf Month = dateAdd("d",-1,dateserial(year(now(),month(now(),1)
will return the last day of july since we are in August.
--
Bob Quintal
PA is y I've altered my email address.
--
Posted via a free Usenet account from http://www.teranews.com
.
- References:
- Create Weekly and Monthly Flag in database/table
- From: Lucas_london via AccessMonster.com
- Re: Create Weekly and Monthly Flag in database/table
- From: Bob Quintal
- Re: Create Weekly and Monthly Flag in database/table
- From: Lucas_london via AccessMonster.com
- Re: Create Weekly and Monthly Flag in database/table
- From: Bob Quintal
- Re: Create Weekly and Monthly Flag in database/table
- From: Lucas_london via AccessMonster.com
- Create Weekly and Monthly Flag in database/table
- Prev by Date: Calculations based on other field values
- Next by Date: Open external help file
- Previous by thread: Re: Create Weekly and Monthly Flag in database/table
- Next by thread: Open a dao recordset
- Index(es):
Relevant Pages
|