Whether the table is set to workday. (if it is set to a non-workday for a holiday, talbe sets whether the day is a workday)
The input date must be a business day.
ALTER function [dbo]. [fn_workdayadd] (@ date datetime, @ days int)
Returns datetime -- nvarchar (100)
As
Begin
Declare @ I int -- computing work days
Set @ I = 1
Declare @ flag nvarchar (10) -- whether it is a working day
WHILE (@ I <= @ days)
BEGIN
If exists (SELECT top 1 flag FROM dbo. BCC_Admin_WorkDay
Where flag = 'y' and convert (nvarchar (10), Date, 120) = convert (nvarchar (10), @ date + 1,120) -- workday
Begin
Set @ I = @ I + 1
Set @ date = @ date + 1
Set @ flag = 'y'
End
Else
Begin
Set @ date = @ date + 1
Set @ flag = 'n'
End
CONTINUE
END
-- The last day is the work day. check whether there is any
While exists (SELECT top 1 flag FROM dbo. BCC_Admin_WorkDay where convert (nvarchar (10), Date, 120) = convert (nvarchar (10), @ date + 1,120) and flag = 'n ')
Begin
Set @ date = @ date + 1
End
Return convert (nvarchar (10), @ date, 120) -- + ''+ @ flag
End