Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

using ssis to create tables dynamically Expand / Collapse
Author
Message
Posted Monday, February 09, 2009 8:17 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, May 17, 2010 8:40 AM
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
Post #652852
Posted Tuesday, February 10, 2009 6:39 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, June 06, 2013 9:34 AM
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)


Post #653641
Posted Tuesday, February 10, 2009 7:43 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, May 17, 2010 8:40 AM
Points: 6, Visits: 41
really? i can't create a table in ssis? do you know which task i use?? thanks
Post #653713
Posted Thursday, February 19, 2009 2:21 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, November 11, 2011 12:01 PM
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! ----
Post #660873
Posted Wednesday, March 11, 2009 6:17 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, September 24, 2012 8:10 AM
Points: 2,042, 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
Post #673154
Posted Thursday, March 12, 2009 5:05 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, November 15, 2010 4:02 PM
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.
Post #674835
Posted Thursday, March 12, 2009 6:03 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, January 21, 2014 8:55 AM
Points: 1,520, Visits: 3,035
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.
Post #674864
Posted Friday, March 05, 2010 3:18 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, June 19, 2012 8:06 AM
Points: 218, Visits: 10,576
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?
Post #877498
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse