SunQuest
           Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old July 29th, 2003, 03:11 PM
justastef justastef is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 16 justastef User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
recordset

Is this possible... I have a recordset with information like this


TableName ColumnDefinition
table1 col1 varchar(20) Null
table1 col2 varchar(10) NotNull
table2 col1 varchar(10) Null
table2 col2 varchar(30) NotNull

I want to build a cursor that will build tables with the table name in the tablename column and with columns defined as such in the column ColumnDefinition.

Obviously I can't just run through each row as itself because I have multiple columns for a same table... anybody have any ideas how to approach this?

Reply With Quote
  #2  
Old July 29th, 2003, 04:32 PM
justastef justastef is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 16 justastef User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I got it... if anyone is interested here is the code:::: of course after declaring neccessary variables... Maybe someone else can use this to their advantage!


Declare CreateTableCursor Cursor For
Select table_name, column_definition
from dbo.db_table_information
order by table_name, ordinal_position

open CreateTableCursor

Set @prevtable = ''
Set @sql = ''

Fetch Next from CreateTableCursor into @table, @coldef

While @@fetch_status = 0
BEGIN
If @prevtable <> @table
BEGIN
If @sql <> ''
BEGIN
Set @sql = @sql + " )"
exec(@sql)
END
Set @sql = "Create table dbo." + @table + "( " + @coldef

END

If @prevtable = @table
BEGIN
set @sql = @sql + ", "
set @sql = @sql + @coldef

END
set @prevtable = @table
Fetch next from createtablecursor into @table, @coldef

END
Close CreateTableCursor
Deallocate CreateTableCursor

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > recordset


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway