Create table from file and then load the data

  • 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.

  • 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?

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • 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.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Thanks. I'll give that a go

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply