Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Rename TableName To Datetime Expand / Collapse
Author
Message
Posted Monday, June 23, 2008 12:04 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, February 17, 2010 12:47 PM
Points: 11, Visits: 109
Hi.

I'm working on a script that moves data from one table to another (This one is created dynamic).

I'm using:

USE ping_statistics
GO
SELECT * INTO PING_Temp
FROM Hostbackup
EXEC sp_rename 'PING_Temp', 'HostInfo_(getdate)'

Where I would like the name of the new table to be

"PING_2008" Where 2008 is the current year.

Can anyone help me here?

\Jan.
Post #521538
Posted Monday, June 23, 2008 2:50 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, August 5, 2014 2:55 AM
Points: 1,101, Visits: 5,280
declare @TableName char(50)
select @TableName = 'PING_' + left(convert(char(50), getdate(), 120), 4)
print @TableName
execute sp_rename 'PING', @TableName
Post #521588
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse