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 2008 Forums
 Transact-SQL (2008)
 Create Table Dynamically

Author  Topic 

Kalaiselvan
Posting Yak Master

112 Posts

Posted - 2011-06-24 : 02:55:48
DECLARE @str nvarchar(500)

set @str= 'CREATE TABLE '+@Tabname +'(
SUBSCRIBER varchar(max) NOT NULL,
PRODUCT_ID varchar(max) NOT NULL,
PRODUCT_DESC varchar(max) NOT NULL,
ADVERTISER varchar(max) NULL,
GROUP_COMPANY varchar(max) NULL,
BRAND varchar(max) NULL,
SUB_BRAND varchar(max) NULL,
CATEGORY varchar(max) NULL,
SUB_CATEGORY varchar(max) NULL
)'

EXEC(@str)

But i need the Above Create table function Dynamically from the Table structure.
No of columns may be increase, hence need the Column names and its Data type from Table in this Create table function.

Regards,
Kalaiselvan R
Love Yourself First....

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-06-24 : 03:58:52
If you want to create a table then it means that the table doesn't exists in this moment.
So where should the needed information come from?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

NeilG
Aged Yak Warrior

530 Posts

Posted - 2011-06-24 : 04:11:14
I really can't understand why or when there'd be a need to ever do this
Go to Top of Page
   

- Advertisement -