March 15, 2010 at 8:43 am
I use following query to rename a table
DECLARE @RenameTableDetail varchar(50)
SELECT @RenameTableDetail = Replace(('WTable' + CAST ( GetDate() AS varchar (50 ))), ' ', '_')
print @RenameTableDetail
IF EXISTS (SELECT * FROM sys.tables WHERE name = 'WTable')
EXEC sp_rename @objname = 'WTable', @newname = @RenameTableDetail
GO
and table is renamed from WTable to WTableMar_15_2010_10:39AM
I would like to remove the timestamp and the '_' from between Mar_15_2010. So the end result name would like:
WTableMar152010
thoughts?
March 15, 2010 at 9:08 am
shahab-205604 (3/15/2010)
I use following query to rename a tableDECLARE @RenameTableDetail varchar(50)
SELECT @RenameTableDetail = Replace(('WTable' + CAST ( GetDate() AS varchar (50 ))), ' ', '_')
print @RenameTableDetail
IF EXISTS (SELECT * FROM sys.tables WHERE name = 'WTable')
EXEC sp_rename @objname = 'WTable', @newname = @RenameTableDetail
GO
and table is renamed from WTable to WTableMar_15_2010_10:39AM
I would like to remove the timestamp and the '_' from between Mar_15_2010. So the end result name would like:
WTableMar152010
thoughts?
You could try replacing you CAST statement with something like:
REPLACE(REPLACE(RTRIM(CONVERT(VARCHAR(12), GETDATE())), ' ', ' '), ' ', '_')
I'd rather use a different date format:
CONVERT(VARCHAR(8), GETDATE(), 112)
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
March 15, 2010 at 11:35 am
I recommend the replace option that was provided.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply