sp_rename with variable

  • Hi,

    I would like to use sp_rename but with a variable to name the new table.

    For example,

    exec sp_rename 'table_1','table_OLD'

    I would ideally like to replace the "OLD" with:

    convert(varchar(50), getdate(),112)

    which would append the date to the rename table.

    This throws up errors. I have tried nesting this in a @sql = '' but with little luck.

    Thanks

    Dave

  • Use this:

    declare @newname varchar(56)

    set @newname = 'table_' + convert(varchar(50), getdate(),112)

    exec sp_rename 'table', @newname

     

  • thats great. should have thought about that one a bit more.

    Thanks

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

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