Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 5th, 2008, 05:36 PM
Registered User
 
Join Date: Dec 2007
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?




 
Old February 6th, 2008, 07:53 PM
Friend of Wrox
 
Join Date: Aug 2004
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


 
Old February 7th, 2008, 10:49 AM
Registered User
 
Join Date: Dec 2007
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


 
Old February 7th, 2008, 07:19 PM
Friend of Wrox
 
Join Date: Aug 2004
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.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Rename a Column using SQL pipelineconsulting Classic ASP Databases 7 September 21st, 2017 04: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.