• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 604
  • Last Modified:

SSIS: Foreach Loop Container

Hi, there are many data files in the folder and I'd like to know the order they will be processed. I am using Foreach Loop Container. Does anyone know how it loops through the files, in alphabetical order or ... ?
1 Solution
I think that it will order by filename, but I haven't tested it very much!  Try putting some files in named a.txt, b.txt, c.txt, etc., but don't add them to the folder in that order. Then see what you get.

To be certain of your order you could read then in in a foreach loop, placing them into a table. Then read the table in the proper order into an Object Variable, and have a ForEach loop read the object variable and not directly from the disk.


Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
The order of file loading is not predictable.  

If you require an ordered loading, I'd use the first ForEach loop to get all file names and insert them into a table.  
Then do a SQL Task to select that list, ordered by however you wish.
Then, go through a loop to set the source to that path-file, and load.
ValentinoVBI ConsultantCommented:
My experience is that files are always processed alphabetically on filename in ascending order.  This order is not guaranteed but to be honest I've never seen it behave any differently.  So you might want to take that small risk and indeed assume they are treated alphabetically.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now