SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Dynamically create a table using date in sp
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sachingovekar
Yak Posting Veteran

99 Posts

Posted - 12/01/2008 :  03:33:53  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 12/01/2008 :  03:45:07  Show Profile  Reply with Quote
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

India
22772 Posts

Posted - 12/01/2008 :  04:43:36  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Why do you want to create table dynamically?


Madhivanan

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

sachingovekar
Yak Posting Veteran

99 Posts

Posted - 12/01/2008 :  08:47:33  Show Profile  Reply with Quote
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
Yak Posting Veteran

99 Posts

Posted - 12/01/2008 :  08:51:05  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 12/01/2008 :  08:53:25  Show Profile  Reply with Quote
you're welcome
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000