Rename TableName To Datetime

  • 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.

  • declare @TableName char(50)

    select @TableName = 'PING_' + left(convert(char(50), getdate(), 120), 4)

    print @TableName

    execute sp_rename 'PING', @TableName

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply