March 26, 2008 at 8:51 am
Hi, does anyone knows how to change the name of a table mixing characters with the result of a query.
Example:
DECLARE @DATE AS VARCHAR (8)
SET SELECT @DATE = CAST(convert(varchar, getdate(), 112)AS VARCHAR(8))
SP_RENAME 'ATT_', 'ATT_' + @DATE
of course this doesn't work but does anyone know how to do it?
Thanks for the help!
FJM
March 26, 2008 at 9:27 am
Your code seems to work fine by just adding another variable.
DECLARE @newname VARCHAR(50)
DECLARE @DATE AS VARCHAR (8)
SET @DATE = CAST(convert(varchar, getdate(), 112)AS VARCHAR(8))
SET @newname = 'ATT_' + @DATE
EXEC SP_RENAME 'ATT_', @newname
March 26, 2008 at 9:32 am
Lol.... it's so easy!!!
March 26, 2008 at 9:33 am
Thanks!!!
March 26, 2008 at 9:50 am
Hi,
DECLARE @tbl SYSNAME, @tbl_new SYSNAME
SELECT @tbl = 'ATT_',
@tbl_new = @tbl + CAST(convert(varchar, getdate(), 112)AS VARCHAR(8))
EXEC sp_rename @tbl, @tbl_new, 'OBJECT'
[font="Verdana"]CU
tosc[/font]
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply