Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


using ssis to create tables dynamically


using ssis to create tables dynamically

Author
Message
Fee01
Fee01
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 41
eg i want to output a new table everytime the code is run showing as part of the tablename the date the code was run..

thanks
patrick ryan-390269
patrick ryan-390269
Grasshopper
Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)

Group: General Forum Members
Points: 13 Visits: 65
You will need to use dynamic sql and the getDate() function.

This should get you started...

@TABLE_NAME VARCHAR(50),
@SQL VARCHAR(MAX),

Set @TABLE_NAME = CONVERT(VarChar(20), GETDATE(), 101)


/* Generate table */
SET @SQL = Add create table sql here.

/* Execute dynamic sql*/
EXEC(@SQL)
Fee01
Fee01
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 41
really? i can't create a table in ssis? do you know which task i use?? thanks
jagadishrashmi
jagadishrashmi
SSC-Enthusiastic
SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)

Group: General Forum Members
Points: 158 Visits: 55
may be there is a reason, but why create table for last run and where do you want to create it?

---- Live and Let Live! ----
beezell
beezell
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2042 Visits: 499
To run that code you will need a SQL Task in the Control Flow view. You probably should save the table name to a global SSIS variable so you can reference it in other places if you are trying to populate it. I'm still not 100% convinced you need a table for each run. Generally you put a time stamp on a record to determine when it was inserted, but you may have a practical application.

Cheers,
Brian
Nugby
Nugby
Old Hand
Old Hand (374 reputation)Old Hand (374 reputation)Old Hand (374 reputation)Old Hand (374 reputation)Old Hand (374 reputation)Old Hand (374 reputation)Old Hand (374 reputation)Old Hand (374 reputation)

Group: General Forum Members
Points: 374 Visits: 266
Yes, you can definitely create Tables using SSIS. In Data Flow Task, create a OLE DB Destination and for the Data Access Mode, select "Table Name or View Name Variable" or "SQL Command" and use some kind of Variable to set the table name. Never actually bothered using it so I'll leave the finer details to yourself or another poster, but you can definitely do it.
john.arnott
john.arnott
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1466 Visits: 3059
Yes, you CAN create a uniquely named table in each run of your SSIS package. You could simply build a create table DDL statement using variables, part of which would be the current date, time or whatever, and run it in an Exec SQL task.

But that doesn't mean you SHOULD do that. As suggested, the date and time could be part of the row definition so you could limit the domain of queries with a simple where clause.

Why not create new tables? A few reasons might be:
-- Variable table names would require any application using the data to build queries dynamically just to find the table name(s). Say you run daily and create a table for each day. What happens when you want to summarize data for a number of days?
-- The overhead of creating tables and indexes (you do want indexes, right?) isn't necessarily enormous, but if not necessary you'll want to avoid it.
-- It could be that in the future, someone will want to define a constraint based on this table (a foreign key....), but then they'll see that it's not a table at all but an ephemeral family of tables. Each new table would then require its own FK definition in the dependant table.
rock on dude
rock on dude
SSC Veteran
SSC Veteran (222 reputation)SSC Veteran (222 reputation)SSC Veteran (222 reputation)SSC Veteran (222 reputation)SSC Veteran (222 reputation)SSC Veteran (222 reputation)SSC Veteran (222 reputation)SSC Veteran (222 reputation)

Group: General Forum Members
Points: 222 Visits: 10576
hi,
according to beezells answer:
if i use a sql task to create a new table in a ssis package, how can i save the name of this table to a global variable?
i'm trying to import serveral excel files. i already created the loop to do this.
but since this is a job that has to be done every month, i need a new table to every month.
what i wanted to do was a put a sql task in front of the excel importing loop to create the table and to assign the table name to a variable, so i can use it for the ole db destination.

anybody an idea how to save the name of the in the sql task created table?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search