|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, April 19, 2013 11:06 AM
Points: 174,
Visits: 423
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 2:04 AM
Points: 1,342,
Visits: 1,946
|
|
I needed a similar feature a few years ago and came up with 8 classifications of International holidays (non-working days) as either fixed or relative to some other date, one of which, I think, is unique to the UK. I handled holidays as single days and haven't checked if your multiple day code will cope with this. I assume it will!
The 8 are: 0 -- fixed date every year (MMDD) 1 -- days relative to Easter (e.g. Whitmonday is Easter Sunday + 50 days) 2 -- Fixed, but if it's at a weekend, it's replaced by the following Monday 3 -- Specific day of week, usually Moday of first (MM01) or last (MM25) week of a month, but could be e.g. Wednesday before MMDD 4 -- As 2, but for the 2nd day of a pair (e.g. Christmas/Boxing days in the UK) 5 -- fixed date in Hijri (Moslem) Calendar 6 -- days relative to Greek Orthodox Easter 7 -- relative to previous winter solstice (Chinese Qing Ming Jie)
The awkward item was 4, UK's Boxing Day holiday. Usually it's considered to be 26th December, but if it falls on a Saturday then it's replaced by havig the Monday (28th) as a holiday. However, if it falls on Sunday or Monday, then it's replaced by Tuesday (27/28th) because Christmas Day will be on Saturday/Sunday and hence will have triggered Monday already being a non-working day. So far, this is the only example I've found where a 2-day holiday gives 2 non-working days. Many countries assume that if a 'religious' holiday falls at a weekend, then no extra days are substituted.
I also collapsed the Easter calculation (for 1900 to 2099) into a single inline calculation (which needed a little tweaking):
when 1 -- days relative to Easter (e.g. Whitmonday is Easter Sunday + 50 days) then dateadd(d,(case @year when 1954 then 14 when 1981 then 14 when 2049 then 14 when 2076 then 14 else 21 end + ((19 * (@year % 19) + 24 ) % 30) + ((2 * (@year % 4) + 4 * (@year % 7) + 6 * ((19 * (@year % 19) +24 ) % 30) + 5) % 7)) +[MonthDayOffset],convert(char(4),@year)+'0301')
I also used a single field as MonthDayOffset, i.e. it either contains a month & day (1225, 0704) or an offset (-2 for Good Friday, 2 days before Easter). This was simply because I could not see any point in a table having 2 columns where either one or the other but never both would be used.
Interesting to see how someone else solved a similar problem.
Derek
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 8:14 AM
Points: 32,910,
Visits: 26,802
|
|
I haven't done a deep dive on all the code but, if this works as advertised, it's an awesome solution for the problem stated. Thanks for taking the time to write it all up and sharing it, Terry.
--Jeff Moden "RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, April 19, 2013 11:06 AM
Points: 174,
Visits: 423
|
|
Greetings Jeff,
It has been a project I have worked on for several years. I have translated the code several times from programming language to SQL backend to full SQL. Some parts may not be pretty but it should work for you. 
Terry Steadman
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Today @ 9:53 AM
Points: 18,744,
Visits: 12,336
|
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Today @ 7:17 AM
Points: 89,
Visits: 1,334
|
|
Nice code.
How is it licensed?
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Friday, February 22, 2013 3:34 PM
Points: 286,
Visits: 661
|
|
Beautiful! Thank you for that very elegant solution to something I've been hashing around with very badly.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 8:22 AM
Points: 3,
Visits: 13
|
|
Very nice solution. I use a solution like that.
I suggest to include region information in holiday table, because a world wide solution needs to know world, national e local holidays.
We need a solution that can inform international holidays, holidays of a country, holidays of a state and holidays of a city.
For example, a national company that has a solution for dealing with demands. A person can send a request for other peson in different cities. Each person has a certain amount of business days to answer a demand. If a person received a demand and he/she works in a city that has a local holiday, her/his deadline for responding it is different from another person in another city that hasn't a local holiday.
Best regards,
Nilson Bonadeu
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, April 19, 2013 11:06 AM
Points: 174,
Visits: 423
|
|
Greetings Robert,
You are free to use the code to learn and your personal projects. If you are planning on using it in a commercial product that is to be sold, then I respectfully ask that you talk with me first.
Have a good day.
Terry Steadman
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, April 19, 2013 11:06 AM
Points: 174,
Visits: 423
|
|
Greetings karyn,
Glad that you were able to find the code useful. If you have any questions, please don't hesitate to ask.
Have a good day.
Terry Steadman
|
|
|
|