Click here to Skip to main content
15,904,823 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to find the next working day after consecutive holidays in sql. I am having holiday master table. In it I am marking holidays. I need to fetch the next working day if there are consecutive holidays after the current date. (Suppose if Nov 25 and Nov 26 are holidays (consecutive) has to fetch Nov 27 as next working day while current date is Nov 24th.
Suppose if Nov 25,Nov 26 and Nov 27 are holidays (consecutive) has to fetch Nov 28 as next working day while current date is Nov 24th

Suppose if Nov 25 and Nov 27 are holidays (non consecutive) then no need to fetch next working day while current date is Nov 24th. 


I need a generic query for the same.

What I have tried:

Below is the table
select HolidayDate,CreatedBy,CreatedDate,Description,WeekDay,IsDeleted,ModifiedBy,ModifiedDate from DDS_HOLIDAY_CONFIGURATION order by 1  desc 
Posted
Updated 24-Nov-20 7:14am

1 solution

I'll give you some logic hints but you'll need to do the work.

First, you can get the day of the week from SQL (look it up) and you need to only consider those days that are work days.

Now, for any given date from your holiday table you can modify the date by incrementing it (there is a SQL function to add time-units to a date - ranging from years to seconds (you can look that up, too).

Now you can increment your holiday by days and find when the day of the week IS a workday and IS NOT in your holiday table.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900