rikroket
asked on
Rename table using dynamic SQL
I would like to rename a table by appending the current date to the front of a table name.
For example:
Rename this table: Table1
To: 02212005_Table1 (month, day, year)
How can I perform this using dynamic SQL or by using sp_rename?
Thanks in advance . . .
Rik
For example:
Rename this table: Table1
To: 02212005_Table1 (month, day, year)
How can I perform this using dynamic SQL or by using sp_rename?
Thanks in advance . . .
Rik
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Missed it by > that< much....well done KarinLoos
ops - wrong post
Hey rikroket....as much as I appreciate the points....I was second with the answer. :-)
set @newname = convert(varchar(2), day(GetDate()) ) + convert( VARCHAR(2) , MONTH(GETdATE()))
+ convert(char(4), Year(getdate()))
set @newname = @newname + '_abc'
exec sp_rename 'Table1', @newname