Click here to Skip to main content
15,867,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to use single quote to execute query to rename column name dynamically. like

declare @TableName nvarchar(100)
set @TableName='TestTable'
EXEC sp_RENAME '@TableName.[OldColumnName]' , 'NewColumnName'

Here I cant define the variable name to rename the column. Please give me the query at your earliest.
Posted
Updated 19-Jul-15 20:52pm
v2

1 solution

You can do the escaping by using two apostrophes.

Consider the following
SQL
SELECT  '''Some data'''

However, I don't think you need to escape the apostrophes since you can pass the whole name inside a variable to the procedure. Try using
SQL
sp_rename @objname = @old_comlumn_name_variable , @newname = @new_column_name_variable, 'COLUMN'
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900