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:24am

do you have static number of file or it may vary?? If it is static then you can load this data with DFT (data flow task) [ie : if you have A, B,C,D,E,F files so it will be one time mapping] else DFT doesn't support the dynamic metadata so there is only way to load this to use script task... Let us TRY this | My Blog :: http://quest4gen.blogspot.com/
Free Windows Admin Tool Kit Click here and download it now
September 18th, 2012 1:53am

do you have static number of file or it may vary?? If it is static then you can load this data with DFT (data flow task) [ie : if you have A, B,C,D,E,F files so it will be one time mapping] else DFT doesn't support the dynamic metadata so there is only way to load this to use script task... Let us TRY this | My Blog :: http://quest4gen.blogspot.com/
September 18th, 2012 2:02am

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:37pm

Number of files are static around 10 but they need not be available at the same time. I want corresponding DFT to be chosen based on file name "Foreach file loop" selects. Is that possible to do is this way instead of executing all DFTs ?
September 19th, 2012 1:49pm

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
Free Windows Admin Tool Kit Click here and download it now
September 19th, 2012 2:09pm

Hi Bonediggler, I am getting below error at step 10 while using variable to select a destination table :
September 19th, 2012 6:09pm

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

Other recent topics Other recent topics