Re: Custom Function in Query
- From: "Baz" <bazz@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 27 Sep 2005 15:58:45 +0100
"Mike" <mikehoar@xxxxxxxxxxxxxxxxxxx> wrote in message
news:1127815905.019772.79200@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> I am converting a mdb to an adp with sql server 2000 backend. I have a
> query in the mdb which uses a custom vba function in an expression
> field to work out the number of working days between two dates. This
> function also uses a table of Bank Holiday dates and a bit of ado to
> take Bank Holiday dates out if they fall within the period.
>
> I have figured out how to create a SQL Server Function to work out the
> weekdays between two dates fed in as arguments which I can then use in
> a View or Stored Procedure. However, I am stumped as to how to
> implement the bit about taking out the bank holidays as well, can
> anyone help? I appreciate I could hard code the dates into the SQL
> Server Function but I would prefer to use a table to store the dates so
> that the user can add or change dates as required.
>
You could create a table that contains a row for EVERY day for, say, the
next 50 years. Only about 18000 rows, not a problem. It would have two
columns:
the_date (primary key)
workday (bit)
It would be pretty easy to create a query which, for every date in the
table, sets the value of workday according to whether it's a weekday. Then,
all you need to do is to manually set the bank holidays for as far ahead as
you can/want to. Having done that, counting the working days between two
dates becomes a simple aggregate query.
Or, you could make it a bit smaller by making it a non-working-day table,
containing just Sats and Suns (pre-loaded) and bank holidays. The counting
queries would still be pretty simple.
.
- References:
- Custom Function in Query
- From: Mike
- Custom Function in Query
- Prev by Date: Re: a newbie question
- Next by Date: Re: Can't setup a logon for a remote computer
- Previous by thread: Re: Custom Function in Query
- Next by thread: Connecting to another DB
- Index(es):
Relevant Pages
|