Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 sp_rename error on stored procedure

Author  Topic 

clerus
Starting Member

8 Posts

Posted - 2008-12-03 : 05:44:56
Hello there!!


Maybe someone could give a solution for this.
Im trying to execute sp_rename for renaming existing column in our tables but it seems not working inside the stored procedure.
So here's the script.

ALTER PROCEDURE [dbo].[uspRenameTableColumn]
AS
DECLARE @renameTableColumn varchar(5000)
SET @renameTableColumn = N'
sp_rename ''tblSample.newcolumn'',''oldcolumn'',''column''
'
EXEC @renameTableColumn
GO

When I run it using the query editor, the result would be "Command(s) completed succesfully" So I assumed it would be fine.

But when I try to execute it..
EXEC uspRenameTableColumn

"It throws back an error saying...

"Msg 2812, Level 16, State 62, Procedure uspRenameTableColumn, Line 7
Could not find stored procedure '
sp_rename 'tblSample.newcolumn','oldcolumn','column''. "

Is there something wrong with the syntax or is there another way around to rename an existing field besides sp_rename?

Your answer would be a great help. Thanks in advance.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-03 : 06:32:46
try putting braces after exec

ALTER PROCEDURE [dbo].[uspRenameTableColumn]
AS
DECLARE @renameTableColumn varchar(5000)
SET @renameTableColumn = N'
sp_rename ''tblSample.newcolumn'',''oldcolumn'',''column''
'
EXEC (@renameTableColumn)
GO
Go to Top of Page

clerus
Starting Member

8 Posts

Posted - 2008-12-03 : 20:22:49
Solved!! Thanks a lot!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-03 : 23:40:51
You're welcome
Go to Top of Page
   

- Advertisement -