I\'ve seen different version of this kind of function for other coding languages (Python, jQuery, etc.) but not for SQL. I have a procedure that needs to have a date calcul
I wrote a SQL function years ago to build a dynamic holiday table as a table function. The link is below:
http://www.joebooth-consulting.com/sqlServer/sqlServer.html#CalendFunc
Hope it helps...
You can access the table function (or your own holiday table) to determine number of holidays via a SQL statement like below
SELECT count(*) FROM holiday_date(2013)
WHERE holiday_date BETWEEN @fromDate AND @toDate
then add the count to the returned date using dateAdd().
If you might have holidays that fall on a weekend, add the following to the WHERE clause
AND DatePart(dw, Holiday_date) != 1) and (DatePart(dw, holiday_date) != 7)