HiI have a situation where I need to Alter a Stored Procedure on a monthly basis and I would like to get rid of the 'Human Touch'. I want to modify the date part of the following code:CREATE PROCEDURE get_load_periodx@load_period datetime outAS SET @load_period = '20050101'GO
I was trying to alter it using the following code. If there's an easier way please let me know:Declare @Load_Period datetime , @nSql NVarchar (150) , @VDate varchar(20)Exec get_load_periodx @Load_Period outSelect @Load_Period as [Load Period]If Month(@Load_Period) In (1,3,5,7,8,10,12) Begin Set @Load_Period = @Load_Period + 31 EndElse If Month(@Load_Period) In (4,6,9,11) Begin Set @Load_Period = @Load_Period + 30 End Else Begin Set @Load_Period = @Load_Period + 28 EndSelect @Load_PeriodSet @nSql = 'Alter Proc get_load_periodx@Load_Period Datetime OutasSet @Load_Period = ' + @Load_PeriodExec Sp_Executesql @nSqlSelect @Load_Period
I can't execute it because the @Load_Period is a datetime datatype and I'm trying to add it to a nvarchar. I also tried casting it(Load_Period) to a varchar but when it has to execute the Stored Procedure can't accept it because it's now a varchar but the SP is expecting a datetime.You can't teach an old mouse new clicks.