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
 General SQL Server Forums
 New to SQL Server Programming
 rename column

Author  Topic 

Clas
Starting Member

33 Posts

Posted - 2010-03-02 : 08:55:28
Hi

How do I get the ' ' in sp_rename ?

@tableOldName VARCHAR(300), --- input: table1.name1
@NewColumnName VARCHAR(100) --- input: name2


EXEC sp_RENAME @tableOldName ,@NewColumnName, 'COLUMN'

Should be like this:
EXEC sp_RENAME 'table1.name1' ,'name2', 'COLUMN'

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-02 : 09:03:38
you dont need '', storing the value in varchar field is enough

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-02 : 09:05:05
declare @sql varchar(8000)

@tableOldName VARCHAR(300), --- input: table1.name1
@NewColumnName VARCHAR(100) --- input: name2

set @sql='sp_RENAME '''+@tableOldName+''','''+@NewColumnName+''',''COLUMN'''

EXEC (@sql)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-02 : 09:06:53
quote:
Originally posted by madhivanan

declare @sql varchar(8000)

@tableOldName VARCHAR(300), --- input: table1.name1
@NewColumnName VARCHAR(100) --- input: name2

set @sql='sp_RENAME '''+@tableOldName+''','''+@NewColumnName+''',''COLUMN'''

EXEC (@sql)

Madhivanan

Failing to plan is Planning to fail


sorry i didnt understand
whats the need of D-SQL here?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-02 : 09:18:44
Yes. No need of Dynamic SQL

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-02 : 09:31:04
quote:
Originally posted by madhivanan

Yes. No need of Dynamic SQL

Madhivanan

Failing to plan is Planning to fail


Ok . Thought I missed something obvious

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-03-02 : 09:35:36
Still i dint get the syntax please rewrite the syntax

Vabhav T
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-02 : 09:37:37
quote:
Originally posted by vaibhavktiwari83

Still i dint get the syntax please rewrite the syntax

Vabhav T


Whci syntax are you talking about?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-02 : 09:38:05
quote:
Originally posted by vaibhavktiwari83

Still i dint get the syntax please rewrite the syntax

Vabhav T


syntax of what?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-03-02 : 09:41:58
SP_Rename

Vabhav T
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-02 : 09:43:57
quote:
Originally posted by vaibhavktiwari83

SP_Rename

Vabhav T


lookup in books online. it has detailed description

http://msdn.microsoft.com/en-us/library/ms188351.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-03-02 : 09:49:28
thanks

Vabhav T
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-02 : 09:54:12
quote:
Originally posted by vaibhavktiwari83

thanks

Vabhav T


welcome!

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -