date/timestamp in table name

  • would someone share with me the command used to create a table with current timestamp or date appended to the name.. e.g.

    create table city06112007

    how can I appened today's date to table name?

    thanks

  • Dynamic SQL.

     

    declare

    @sql varchar(2000)

    select

    @sql = 'create table TableName' + convert(varchar(12), getdate(), 112) + '(

    C1 int);'

    exec

    (@sql)

     

  • I used following and it worked:

     

    DECLARE

    @RenameTableDetail varchar(50)

    SELECT

    @RenameTableDetail = Replace(('TableDetail' + CAST ( GetDate() AS varchar (50 ))), ' ', '_')

    print

    @RenameTableDetail

    EXEC

    sp_rename @objname = 'TableDetail', @newname = @RenameTableDetail

    GO

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

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