Home Forums SQL Server 2008 T-SQL (SS2K8) Need Help Creating a Loop for Dynamic Stored Procedure RE: Need Help Creating a Loop for Dynamic Stored Procedure

  • Apologies, the template is created via another action. I need to update the data.

    The two separate function are used in conjunction with our holidays table.  They are also used in determining the roll of the date set when a follow up date lands on a weekend or holiday. should the date be set for the Friday before the weekend or the Monday after...

    I've taken your advise and removed the Dynamic SQL, however, I'm still having a problem using the AddBusinessDays and SubtractBusinessDays functions.  Any idea's?

       
    --@Function wont run as @days is not longer declared
    Declare @Function as varchar(30) = Case WHEN @Days < 0 THEN 'dbo.fn_SubtractBusinessDays' Else 'dbo.fn_AddBusinessDays' END

    update Bankruptcy_Tracking
        SET Follow_Up = CONVERT(DATE,@Function(@Completed,BTC.[Days])) FROM Bankruptcy_Tracking as BT LEFT OUTER JOIN Bankruptcy_Tracking_Config as BTC on BT.Process_ID = BTC.Process_ID and BTC.Process_Order = BT.Process_Order
                    WHERE BTC.Process_ID = @Process_ID AND BTC.Trigger_ID = @Process_Order AND TS = @TS