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 Table Help

Author  Topic 

Red5
Starting Member

3 Posts

Posted - 2011-03-04 : 06:28:47
I am trying to rename that has a Year in it, so that every Year the Year is updated, i.,e. this Year its 2011, but next year iot should say 2012.
I have tried using sp_rename, but nothing I do works, below is one script I have used;
sp_rename Test_Table_1 , Test_Table + select convert(varchar(4), datepart(year,getdate())-1)

Can anyone help?

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2011-03-04 : 06:55:59
Try this -

DECLARE @SQL VARCHAR(1000)
SET @SQL = 'sp_rename Test_Table_1 , Test_Table' + convert(varchar(4), datepart(year,getdate())-1)
EXEC ( @SQL )

Vaibhav T

If I cant go back, I want to go fast...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-03-10 : 10:43:04
Why do you want to rename it every year?

Madhivanan

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

- Advertisement -