SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Importing files in multiple folders at the same time using ssis


Importing files in multiple folders at the same time using ssis

Author
Message
dbman
dbman
SSChasing Mays
SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)

Group: General Forum Members
Points: 655 Visits: 1537
I have 10 folders each receiving a .csv file on a daily basis. I would like to create a package to import these files into a database on a daily basis.


Data/Ab1/mon.csv

Data/Ab2/mon.csv

Data/Ab2/mon.csv


I know i could probably create single packages for each file import in each folder but i would like to know if i can create a single package to to run all the imports at the same time.

Can anyone explain the steps to do this?

I understand i can use a Foreach Loop Container..but I am a little unsure how.

Regards
aaron.reese
aaron.reese
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2371 Visits: 907
The short answer is yes :-D

Are the files going into the same table, if so is there any need to identify which file or folder they came from. If not then you can just use Bulk Insert Task.

If the data is going to different tables or needs the file identifier on it then you will need to use a Data flow Task and the data transormation options to insert, convert and lookup column values

Are the folder names dynamic, If not then the BFI (Brute Force and Ignorance) method would be best: Create 10 FlatFileConnections

If they are dynamic then you can change the connection string of the FlatFileConnection string using an expression, but the formats of the source files must be the same.
dbman
dbman
SSChasing Mays
SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)

Group: General Forum Members
Points: 655 Visits: 1537
Yes the files are going into the same table. There is no need to identify which folder they came from. Ive looked at the Bulk Insert Task, but am a little unsure how to Bulk insert multiple files in these multiple folders.
anthony.green
anthony.green
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23880 Visits: 6519
Use a for each loop with the transverse subfolders option set and then you can change the connectionstring of the csv connection manager dynamically.



Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
When a question, really isn't a question - Jeff Smith
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


aaron.reese
aaron.reese
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2371 Visits: 907
@Anthony.

Do you mean change the FlatFileConnection on each loop (i.e. 10 FFCs and choose each one dynamically) or do you mean one FFC and change it's source in each loop.

To be honest, if it is really only 10 folders and the folders are static, I would just set up 10 bulk insert tasks with 10 FFCs and be done with it ;-)
anthony.green
anthony.green
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23880 Visits: 6519
1 ForEach loop with 1 flat file connection, grabs the files from a sub folder, changes the connection string of the ffc at loop time.

The issue now comes down with are the files and folder names static or can they change and what happens to the file after it has been imported, which will determine which way to write the package



Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
When a question, really isn't a question - Jeff Smith
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search