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 2000 Forums
 Transact-SQL (2000)
 sp_rename to a variable name.

Author  Topic 

mdelgado
Posting Yak Master

141 Posts

Posted - 2002-08-02 : 18:09:42
Hello all.

I would like to execute the sp_rename proc to rename a table to a variable.

i.e.

declare @NewName
set @NewName = 'abc'

exec sp_rename 'OldTable',@NewName

Any ideas? thanks...

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-08-02 : 18:32:56
Some dynamic SQL:

declare @NewName
set @NewName = 'abc'

exec ('sp_rename ''OldTable'',' + @NewName + '''')


Should do the trick. Might need to play with the apostrophes though.

Go to Top of Page
   

- Advertisement -