USE ProdDUTASJobSchedule;
GO
-- Returns the next valid workday on or after the given date
CREATE OR ALTER FUNCTION dbo.fn_GetNextWorkday (@InputDate DATE)
RETURNS DATE
AS
BEGIN
    DECLARE @Workday DATE = @InputDate;

    WHILE DATENAME(WEEKDAY, @Workday) IN ('Saturday','Sunday')
          OR EXISTS (SELECT 1 FROM dbo.FederalHolidays WHERE HolidayDate = @Workday)
    BEGIN
        SET @Workday = DATEADD(DAY, 1, @Workday);
    END

    RETURN @Workday;
END;
