Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Determine number working day between two dates - response (3) by VBurmist

$
0
0

CT A(START_DATE DATE,END_DATE DATE);

INS INTO A VALUES('2013-06-03','2013-06-13');

INS INTO A VALUES('2013-06-06','2013-06-12');

INS INTO A VALUES('2013-06-05','2013-06-22');

CT B(HOL_DATE DATE, BANK_HOLIDAY CHAR(1));

INS INTO B VALUES('2013-06-01','Y');

INS INTO B VALUES('2013-06-02','Y');

INS INTO B VALUES('2013-06-09','Y');

INS INTO B VALUES('2013-06-08','Y');

INS INTO B VALUES('2013-06-15','Y');

INS INTO B VALUES('2013-06-16','Y');

INS INTO B VALUES('2013-06-22','Y');

INS INTO B VALUES('2013-06-23','Y');

 

select start_date, end_date, 

    end_date-start_date+1 as period_length, 

    sum(case when b.bank_holiday='Y' then 0 else 1 end) as working_days,

    sum(case when b.bank_holiday='Y' then 1 else 0 end) as holiday_days

from a

join sys_calendar.CALENDAR as c

on c.calendar_date between a.start_date and a.end_date

left join b ON c.calendar_date = b.hol_date

group by 1,2

order by 1,2


Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>