I have a script to update my database for a new version of my web application. In this update, I need to modify the stored procedure. I have an ALTER PROCEDURE script program that works fine when run by itself, however, when I add it to my script update and run it, I get errors "Incorrect syntax next to the keyword" PROCEDURE "." and "Must declare scalar variable" @age "". What am I doing wrong here? The script looks like this:
BEGIN TRY
BEGIN TRANSACTION
IF EXISTS
(
SELECT * FROM SystemParameters WHERE Name = 'Version' AND Value = '0.1'
)
BEGIN
ALTER PROCEDURE ClearCache
@age int = 120
AS
BEGIN
DECLARE @timestamp DATETIME
SELECT @timestamp = DATEADD(MINUTE, -@age, GETDATE())
END
UPDATE SystemParameters SET Value = '0.2' WHERE Name = 'Version'
END
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
DECLARE @ErrorMessage NVARCHAR(4000);
DECLARE @ErrorSeverity INT;
DECLARE @ErrorState INT;
SELECT
@ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE();
RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState)
END CATCH
Any help would be appreciated :)
source
share