Hi J Gravelle,
I had a similar solution involving 2 functions - 1 to work out when the next working day is (including the current date) and 1 to apply this function x times over. The other difference is that this includes a country code to take into account differing international holidays.
I have also created the opposite functions to calculate x number of business days in the past (used to find all transactions x business days ago)
CREATE FUNCTION fnGetBusinessDateForward (@countryid int, @date date)
RETURNS date
AS
BEGIN
if datepart(dw, @date) in (1,7) or exists(select holidayid from tb_holiday where countryid=@countryid and holidaydate=@date) select @date = dbo.fnGetBusinessDateForward(@countryid, @date + 1)
return @date
END
CREATE FUNCTION fnGetTPlusBusinessDay (@date date, @countryid int, @tplus int)
RETURNS date
AS
BEGIN
while @tplus > 0
begin
SELECT @date = dbo.fnGetBusinessDateForward(@countryid, @date + 1), @tplus = @tplus - 1
end
return dbo.fnGetBusinessDateForward(@countryid, @date)
END