What do you mean by working days?
Monday through friday/saturday?
Including/excluding public holdays, e.g. christmas/eastern/local holidays?
For a complex calculation the only way is probably to use a calendar table with info about working days.
Then it's a simple
select
count(*)
from
mycalendar
where
calendardate between :startdate and :enddate;
If you really just trying to calculate the number of days, that don't fall on Saturday or Sunday you can use following algorithm:
The number of whole weeks * 5 +
the number of remaining days, that don't fall on Saturday or Sunday
In Teradata the number of whole weeks is
((enddate - startdate + 1) / 7) * 5
and weekday is calculated by
(((startdate - DATE '0001-01-01') mod 7) + 1)
this returns the ISO weekday, i.e. Monday = 1
select
/** The number of whole weeks * 5 **/
((enddate - startdate + 1) / 7) * 5 +
/** the number of remaining days, that don't fall on Saturday or Sunday **/
(case when (enddate - startdate + 1) mod 7 < 1
or (((startdate - DATE '0001-01-01') mod 7) + 1) in (6,7)
then 0 else 1 end) +
(case when (enddate - startdate + 1) mod 7 < 2
or (((startdate + 1 - DATE '0001-01-01') mod 7) + 1) in (6,7)
then 0 else 1 end) +
(case when (enddate - startdate + 1) mod 7 < 3
or (((startdate + 2 - DATE '0001-01-01') mod 7) + 1) in (6,7)
then 0 else 1 end) +
(case when (enddate - startdate + 1) mod 7 < 4
or (((startdate + 3 - DATE '0001-01-01') mod 7) + 1) in (6,7)
then 0 else 1 end) +
(case when (enddate - startdate + 1) mod 7 < 5
or (((startdate + 4 - DATE '0001-01-01') mod 7) + 1) in (6,7)
then 0 else 1 end) +
(case when (enddate - startdate + 1) mod 7 < 6
or (((startdate + 5 - DATE '0001-01-01') mod 7) + 1) in (6,7)
then 0 else 1 end) as workingdays
from
(
select
date '2003-01-06' as startdate,
date '2003-01-17' as enddate
) dt
Dieter