Search code examples
csvssisgroupingforeach-loop-container

SSIS 2008 - ForEach Loop to look at specific group/list of files


Ive been searching the internet to what I thought would be a straight forward question to answer. Hope you guys can help?

I am using for each loop to look for specific files and move them with file system task to a different folder.

Say I have 10 csv files. called listed A to J

I only want to move a,e and j but cant seem to get the foreachloop to look for that group.

In the enumerator Files text box i have tried inserting the 3 file names split by various separators, but SSIS thinks its all one specific file and none of the 3 get moved.

Can someone advise how it can be done? Just to confirm, I dont to use wild card logic just group of specific file names - similur to the IN function of SQL query

Thanks in advance

now added img - please advise how to slect 3 specific files in the text box with arrow


Solution

  • Since OP isn't able to proceed with just my comment, I'll explain a bit more in detail -

    1. Use an EXECUTE SQL TASK to dump the names of the files needed into an SSIS object (to do this you could use a stored procedure or an SQL query). Create an object-type variable in the variables tab prior, change the output in the EXECUTE SQL TASK to Full Result Set and map the result to the object you just created. Now this object holds the list of files you need to loop through.
    2. Now drag-and-drop a ForEach container from the SSIS toolbox. It should be configured as a ForEach ADO Enumerator and map the object to it. Create another variable of type string that will hold the file names after each iteration of the ForEach container. Map this also in the Variables tab of the ForEach container.
    3. Now, place the File System Task which you would use to move these files into the ForEach loop. Use the file-name-variable you created to move just the required files.

    Now if you're not sure what SQL query to use for your case in step 1 to get the 3 file names -

    SELECT 'A.csv'
    UNION
    SELECT 'E.csv'
    UNION 
    SELECT 'J.csv'