Looping over files with the Foreach Loop and loading to diffrent ...

  • Hi Everybody,

    i am facing scenario some thing like this.

    i have 10 csv in a folder. so i need to load all the data of 10 csv to different table.

    What i have tried is:

    i used FOR EACH LOOP container to read all the 10 csv files... but its loading all the data of 10 csv files to single table.

    please let me know if there are any ways to do it.

    Thanks in advance

  • This was solution posted by weehyong..

    thanks to u ..

    Assuming the following

    - All the CSV files are of the same format (assuming your files are table_1.csv, table_2.csv, ...)

    - All the 10 tables you are writing to are of the same format

    You can do the following:

    This will load table_1.csv to table_1, table_2.csv to table_2, etc.

    Create a package scope variable

    - CSVFileName, (String)

    - Remember to set it's value to any value (or the name of the first table you want to insert into)

    Create a Foreach Loop Container

    Enumerator: Foreach File Enumerator

    Folder: Retrieve file name: Name only (this will give you only table_1)

    Variable Mappings

    Map User::CSVFileName to Index 0

    Add a Data Flow Task in the Foreach Loop Container

    Consists of

    Flat File Source and an OLE DB Destination

    Two Connection Managers (Flat File Source, and OLE DB Destination)

    For the connection manager, Flat File Source

    Click Expressions

    Choose the ConnectionString property

    Use the expression:

    " " + @[User::CSVFileName] + ".csv"

    For the OLE DB Destination

    Select Data Access Mode: Table name or view name variable

    In the Variable Name, select User::CSVFileName

  • Hello,

    Please I am having same problem. I was wondering if this solution resolved the initial problem.

    I need help on how to resolve this problem because I am facing the same issue.

    Thanks

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

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