Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 5th, 2008, 05:36 PM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default rename column name dyanmically

I want to rename the column name by using the dynamic value
as like

declare @name as varchar(12)
set @name='ss'
sp_rename 'dbo.employees.id3',@name, 'COLUMN';
go

but it shows the error
Incorrect syntax near 'sp_rename'.

any idea?




Reply With Quote
  #2 (permalink)  
Old February 6th, 2008, 07:53 PM
Friend of Wrox
 
Join Date: Aug 2004
Location: Orange County, CA, USA.
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

build a command string and then execute it.

something like:
set @cmd = 'sp_rename ''dbo.employees.id3'',' + @name + ', ''COLUMN'''

then execute @cmd


Reply With Quote
  #3 (permalink)  
Old February 7th, 2008, 10:49 AM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi
thanks for the reply.
now i am getting the following error.

Could not locate entry in sysdatabases for database 'sp_rename'dbo'. No entry found with that name. Make sure that the name is entered correctly.

help me.






Quote:
quote:Originally posted by robprell
 build a command string and then execute it.

something like:
set @cmd = 'sp_rename ''dbo.employees.id3'',' +††@name + ', ''COLUMN'''

then execute @cmd


Reply With Quote
  #4 (permalink)  
Old February 7th, 2008, 07:19 PM
Friend of Wrox
 
Join Date: Aug 2004
Location: Orange County, CA, USA.
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think you need to do master.dbo.sp_rename

or whatever database it is in that your using it with.

If you specify the fully qualified name I think that should fix your problem.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rename a Column using SQL pipelineconsulting Classic ASP Databases 7 September 21st, 2017 05:16 PM
how to use rename method ajeshss C# 1 February 23rd, 2012 08:14 PM
copy and rename red_fiesta Classic ASP Professional 1 November 8th, 2006 11:00 AM
Rename node name venutm XML 0 March 9th, 2006 03:36 PM
Rename a column JENKINSACTIVE SQL Server 2000 3 December 16th, 2004 01:11 AM



All times are GMT -4. The time now is 07:31 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.