views:

2296

answers:

2

Within a Foreach loop in SSIS is there a way that if a task fails you can break out of the loop to the next iteration?

I am looping over xml files and performing a lookup using values within this file, if the lookup doesn't return any values i'd like to report on this and then not perform any other tasks for this file. If there is no equivalent to a break statement how else can this be achieved?

A: 

The lookup can redirect if there are no values returned, away from the successful flow.

You need the rest of your foreach loop to know there has been an error, so one way would be to set a package variable on error, just before you do the logging.

Then, in the 'success' arrow after your lookup you can change it to a conditional success, so that it only proceeds if the value of the variable is not the error value.

Rich
+1  A: 

You could also use a 'for' loop with a boolean condition such as looping while a variable is equal to true. Then when you want to break out of that loop, simply change the value of that variable to false and then you will break out of the loop.

Answering your question...a foreach loop, loops over a collection and other enumerable constructs so long as they exist to loop over. So you could either find a workaround, or just use a 'for' loop instead of a 'foreach' loop. That way you have more of a programming type control over the loop because you set the condition expression.

Jobo