[quoted text, click to view] Arnie Rowland wrote:
> You may benefit from the use of a Calendar Table.
>
> See:
>
> Datetime -Calendar Table
>
http://www.aspfaq.com/show.asp?id=2519 >
> Datetime -How to count the number of business days
>
http://www.aspfaq.com/show.asp?id=2453 >
Note that if you are dealing wil large date ranges, such as 20 days or
more,
you can speed up your queries if you add to your Calendar table another
column NumBusinessDay.
SELECT DateFrom, IsBusinessDay D, NumBusinessDay FROM Dates WHERE
[DateFrom] BETWEEN '20061220' AND '20061230'
DateFrom D
NumBusinessDay
------------------------------------------------------ ----
--------------
2006-12-20 00:00:00.000 Y 86
2006-12-21 00:00:00.000 Y 87
2006-12-22 00:00:00.000 Y 88
2006-12-23 00:00:00.000 N 88
2006-12-24 00:00:00.000 N 88
2006-12-25 00:00:00.000 N 88
2006-12-26 00:00:00.000 Y 89
2006-12-27 00:00:00.000 Y 90
2006-12-28 00:00:00.000 Y 91
2006-12-29 00:00:00.000 Y 92
2006-12-30 00:00:00.000 N 92
(11 row(s) affected)
-- 5 business days from 20061220
SELECT DateFrom FROM Dates WHERE NumBusinessDay =
(SELECT NumBusinessDay FROM Dates WHERE [DateFrom] = '20061220') + 5
AND IsBusinessDay = 'Y'
DateFrom
------------------------------------------------------
2006-12-28 00:00:00.000
(1 row(s) affected)
-- number of business days between '20061220' and '20061230'
SELECT (SELECT NumBusinessDay FROM Dates WHERE [DateFrom] = '20061230')
-
(SELECT NumBusinessDay FROM Dates WHERE [DateFrom] = '20061220')
BusinessDaysBetween
BusinessDaysBetween
-------------------
6
(1 row(s) affected)