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

Create table from file and then load the data Expand / Collapse
Author
Message
Posted Tuesday, October 15, 2013 2:46 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, February 03, 2014 9:44 AM
Points: 32, Visits: 138
Hi,

is there a way via SSIS to create a table to match a file's headers (which can change), and then load that data into the table? I've been looking at BCP, batch load, & script task but can't find the best way.
Post #1504650
Posted Tuesday, October 15, 2013 2:52 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 4:41 AM
Points: 4,828, Visits: 11,180
g_demetriou (10/15/2013)
Hi,

is there a way via SSIS to create a table to match a file's headers (which can change), and then load that data into the table? I've been looking at BCP, batch load, & script task but can't find the best way.


Nothing easy. So you want a new table every time? What would it be called? How would the column data types be determined?



Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
Post #1504653
Posted Tuesday, October 15, 2013 2:57 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:41 PM
Points: 12,201, Visits: 9,156
You'll need to read the first line of the file (easiest way is a script task), get the individual column names and create a dynamic CREATE TABLE statement using those columns. The easiest method is to give every column a fixed data type, such as varchar(250) NULL.

After the table is created, you can use bcp or BULK INSERT to import the flat file into the table.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1504655
Posted Tuesday, October 15, 2013 4:43 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, February 03, 2014 9:44 AM
Points: 32, Visits: 138
Thanks. I'll give that a go
Post #1504674
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse