Reputation: 2516
Is there a way to rename stored procedure dynamically.
For Example:
if my procedure name is:'usp_sg_Cons_Data'
I want to do something like:
EXEC sp_rename 'usp_sg_Cons_Data','usp_sg_Cons_Data__' + Current datetimestamp
So if i Execute the above it should rename 'usp_sg_Cons_Data' to 'usp_sg_Cons_Data__201111081402'
Is there a way to do it?
Upvotes: 0
Views: 2288
Reputation: 432180
DECLARE @oldname varchar(100), @newname varchar(100);
SET @oldname = 'usp_sg_Cons_Data'
SET @newname = @oldname + CONVERT(varchar(20), GETDATE(), 120)
EXEC sp_rename @oldname,@newname
Pick your chosen CONVERT style here
Upvotes: 4