Skip to content
Advertisement

Show jobs over 3 BUSINESS DAYS old

Can someone offer any help on how I would amend the SQL code to show jobs that are over 3 BUSINESS DAYS old?

I have the following code:

select
central_enquiry.enquiry_number,
central_enquiry.enquiry_time,
central_enquiry.officer_code,
type_of_service.service_code,
type_of_service.service_name,
enquiry_subject. subject_code,
enquiry_subject.subject_name,
central_site.site_name,
central_enquiry.enquiry_address,
central_enquiry.enquiry_desc,
enquiry_status.enq_status_code,
enquiry_status.enq_status_name,
central_enquiry.log_effective_date,
central_enquiry.follow_up_date,

CASE
when round((SYSDATE - central_enquiry.enquiry_time),2) >=3 then 'Over 3 days'
else ''
end as Days_since_reported


from
central_enquiry
inner join enquiry_subject on enquiry_subject.subject_code = central_enquiry.subject_code
inner join type_of_service on type_of_service.service_code = enquiry_subject.service_code
inner join enquiry_status_log on central_enquiry.enquiry_number = enquiry_status_log.enquiry_number and central_enquiry.enquiry_log_number = enquiry_status_log.enquiry_log_number
inner join enquiry_status on enquiry_status.enq_status_code = enquiry_status_log.enq_status_code
inner join central_site on central_site.site_code = central_enquiry.site_code


where
type_of_service.service_code = 'ECPE' and
round((SYSDATE - central_enquiry.enquiry_time),2) >=3 and
central_enquiry.officer_code = 'BSO' and
central_enquiry.outstanding_flag = 'Y'


order by central_enquiry.enquiry_number

This shows me all jobs that have been logged more than 3 days ago based on the current date.

where  round((SYSDATE - central_enquiry.enquiry_time),2) >=3 

However I want this to only show me the jobs that have been logged more than 3 BUSINESS days ago – so if a job was logged on Thursday 13th Feb – it would only show in the report when it was past the same time on Tuesday 18th Feb.

Advertisement

Answer

You need to manipulate your condition as following:

where round((SYSDATE - central_enquiry.enquiry_time),2) 
- case when to_char(SYSDATE,'dy') in ('mon','tue') then 2 else 0 end >=3

Cheers!!

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement