Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Creating a Table Name with Date Stamp

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-07-15 : 07:53:57
Erwin writes "I am mining about 2 million records monthly on a table (a total of 10 tables), How can I archive this tables using a Date Stamp naming? I wanted to create this under a Stored Procedure.
example: myTable07062005
where myTable is the current table name and 07062005 would be the date I pulled it.

(TABLES)
.
myTable05022005
myTable06052005
myTable07062005
.
.
.

I am working on SQL server 2000/win 2000/ASP...Thanks! Erwin"

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2005-07-16 : 00:40:48
Perhaps something like this:
DECLARE @str varchar(500), @date char(8)
SET @date = REPLACE(CONVERT(char(10), getdate(), 101), '/', '')
SET @str = 'CREATE TABLE myTable' + @date + '(
col1 int NULL)'
EXEC(@str)


Or:
DECLARE @str varchar(500), @date char(8)
SET @date = REPLACE(CONVERT(char(10), getdate(), 101), '/', '')
SET @str = 'sp_rename ''myoldtable'', ''mytable' + @date + ''''
EXEC(@str)

Go to Top of Page
   

- Advertisement -