How do I load files inside a directory to their respective table based on their file name ?
I have multiples files inside a directory with different name. For example, I have 3 Files with name A, B and C. I want data from file A to be loaded in Table A , File B to be loaded in Table B and so on. Any help will be appreciated!
September 18th, 2012 1:14am

Assuming the number and name(s) of the files is dynamic (i.e. potentially a different number of files with different names every time you run the package), and you will be creating new tables each time based on the file names, you might also consider employing a For Each Loop container with a variable of type string. > Loop the files > Assign the file name to the variable > Create a table based on the value of the variable > Load the data (data flow task inside the For Each Loop container) > Repeat This way you don't necessarily have to use a script task.Bonediggler
Free Windows Admin Tool Kit Click here and download it now
September 18th, 2012 3:28pm

You only need one DFT inside a For Each Loop container. 1) Configure For Each Loop container to have a For Each File enumerator 2) Create 2 variables: FileName and TableName 3) Under Variable Mappings in the For Each Loop container select User:FileName for Index 0 and User:TableName for Index 1 4) Create a connection manager to an existing file 5) In the property window for the connection manager under "Expressions" set ConnectionString to equal variable User:FileName 6) Put a DFT inside the Loop container 7) In the DFT place a Flat File Source 8) For the Flat File Source connection manager, use the one created in #4 above 9) In the DFT put an Ole DB destination 10) Under data access mode, select Table Name or View Name variable 11) Put User:TableName as the variable This setup will loop whatever files are in the folder and put the data into the Table based on the file name. Bonediggler
September 19th, 2012 1:57pm

Hi Bonediggler, I am getting below error at step 10 while using variable to select a destination table :
Free Windows Admin Tool Kit Click here and download it now
September 19th, 2012 5:57pm

Did you assign a variable for the table name? Is it actually the name of a table in the database? If the table doesn't exist yet you would need to create it for the sake of the initial package setup. Bonediggler
September 20th, 2012 9:20am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics