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)
 Dynamically create a table using date in sp

Author  Topic 

sachingovekar
Posting Yak Master

101 Posts

Posted - 2008-12-01 : 03:33:53
Hi,

I want one table to be created using current date in my stored procedure.

For eg: today is 1st Dec 08, then if i run my stored procedure my table should have todays date
for eg: TABLENAME_011208

Please help me on this.

Regards,
Sachin

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-01 : 03:45:07
you need to use dynamic sql. something like

DECLARE @Sql varchar(8000)
SET @sql='CREATE TABLE TABLENAME_' + REPLACE(CONVERT(varchar(10),GETDATE(),4),'.','') +
'(column1 datatype1,column2 datatype.....
)'

EXEC(@Sql)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-12-01 : 04:43:36
Why do you want to create table dynamically?


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sachingovekar
Posting Yak Master

101 Posts

Posted - 2008-12-01 : 08:47:33
quote:
Originally posted by madhivanan

Why do you want to create table dynamically?


Madhivanan

Failing to plan is Planning to fail



i have to process data per week which need to be stored in a table_date

so i will have each weeks data in seperate table
Go to Top of Page

sachingovekar
Posting Yak Master

101 Posts

Posted - 2008-12-01 : 08:51:05
quote:
Originally posted by visakh16

you need to use dynamic sql. something like

DECLARE @Sql varchar(8000)
SET @sql='CREATE TABLE TABLENAME_' + REPLACE(CONVERT(varchar(10),GETDATE(),4),'.','') +
'(column1 datatype1,column2 datatype.....
)'

EXEC(@Sql)




Thanks this will help a lot.

Best Regards,
Sachin
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-01 : 08:53:25
you're welcome
Go to Top of Page
   

- Advertisement -