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)
 Create Table

Author  Topic 

asarak
Starting Member

36 Posts

Posted - 2006-08-09 : 05:25:27
Hi guys, i have a question
i try to create a table dynamically, with the following ...


declare @a varchar(20)
set @a='tbl_'+convert(varchar(15),getdate(),105)
select @a

create table @a (i int, b char(10))
go

that is obvious uncorrect, is there any idea how to
create this??
The purpose is to create dynamically a table and store some data
daily in different tables....

thanks a lot
regards
ASARAK

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-08-09 : 05:35:58
[code]
declare @a varchar(20)
Declare @QryString varchar(800)
set @a='tbl_'+convert(varchar(15),getdate(),105)

Set @QryString = 'Create Table ' + @a + '(i int, b Char(10))'
exec(@QryString)

Set @QryString = 'Select * From ' + @a
exec(@QryString)
[/code]

Chirag
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-08-09 : 09:51:02
Read more about Dynamic SQL

http://www.sommarskog.se/dynamic_sql.html


Madhivanan

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

- Advertisement -