Documente Academic
Documente Profesional
Documente Cultură
of business days. The considerations in calculating 'n' no. of business days are:
Through out this post, all dates hardcoded in the SQL queries are the input dates
which must be passed at run-time. The desired result for us is to fetch all hires just
10 days prior to a given date from JOB record. To achieve this, first we need to find
out the 10th business day from a given date. I have listed all the SQL queries I used
iteratively from the scratch to reach to the desired 'n'th business day.
3) Query gives 'n' number of rows for each day from the input date where 'n' is
the number in rownum condition:
SELECT
TO_DATE ('31-dec-2008', 'DD-MON-YYYY') + rownum the_date
FROM
all_objects
WHERE
ROWNUM < 10;
6) This query gives a date 10 days prior to a given date excluding weekends
and holidays:
SELECT MIN(busdate) AS tendaydate
FROM (SELECT busdate, busday
FROM (SELECT to_date('30-Nov-2009', 'DD-MON-YYYY') - rownum + 1
busdate,
(to_char(to_date('30-Nov-2009') -rownum + 1, 'DY')) busday
FROM all_objects
ORDER BY 1) NO_WKEND
WHERE to_char(NO_WKEND.busdate, 'DY')
NOT IN ('SAT', 'SUN')
AND NO_WKEND.busdate
NOT IN (SELECT to_char(holiday)
FROM ps_holiday_date
WHERE holiday_schedule
= 'Reqd_Schedule'))
ORDER BY 1 DESC) NO_WKEND_HOLID
WHERE rownum < 11;
Note: In the last line of the SQL, in the condition - 'WHERE rownum < 11' number 11
gives the 10th business day prior to a given date. To get the 30th business day 'use
rownum < 31'. The number used here must be 'n'+1 to find the 'n'th business day.
7) This query gives hires from JOB record prior to 10 days (our desired result):
SELECT * from PS_JOB A
WHERE A.HIRE_DT = (SELECT MIN(busdate) AS tendaydate
FROM (SELECT busdate, busday
FROM (SELECT to_date('30-nov-2009', 'DD-MON-YYYY') -
rownum + 1 busdate, (to_char(to_date('30-nov-2009') -rownum + 1, 'DY')) busday
FROM all_objects
ORDER BY 1) NO_WKEND
WHERE to_char(NO_WKEND.busdate, 'DY') NOT IN ('SAT',
'SUN')
AND NO_WKEND.busdate
NOT IN ((SELECT to_char(holiday)
FROM ps_holiday_date
WHERE holiday_schedule
= 'Reqd_Schedule'))
ORDER BY 1 DESC)NO_WKEND_HOLID
WHERE rownum < 11);