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?

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • 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