This is a UDF that counts the days between two dates ignoring weekends and corporate holidays (as supplied in a lookup table). This ignores the time component but could be adjusted should you need to. If both days are on the same work day then the elapsed days is considered 1. If started Monday and completed Tuesday it returns 2. Started Saturday and completed Sunday returns 0. Started Monday and completed the following Monday returns 5. And so on. Holidays are treated the same way as weekends.
This assumes the holiday lookup table is named tblHolidays and the column containing the date (at midnight) is named HolidayDt.
Example Execution yields 9 days less your holidays (8 with Labor day):
select dbo.ElapsedBusinessDays( '9/1/2004', '9/13/2004' )
A Normalization Primer
For most DBAs, normalization is an understood concept, a bread and butter bit of knowledge. However, it is not at all unusual to review a database design by a development group for an OLTP (OnLine Transaction Processing) environment and find that the schema chosen is anything but properly normalized. This article by Brian Kelley will give you the core knowledge to data model.
2003-01-13
18,614 reads