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?
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.
The Foreach Loop container repeats the control flow for each member of a specified enumerator. SQL Server Integration Services provides the following enumerator types: Foreach ADO enumerator to enumerate rows in tables. For example, you can get the rows in an ADO recordset.
A foreach loop is very similar to a for loop, except there is no evaluation phase. This is because you are looping over a collection of objects, and for each object in the collection, you execute a specific statement.
A FOREACH loop begins with the FOREACH keyword and ends with END FOREACH. Between FOREACH and END FOREACH, you can declare a cursor or use EXECUTE PROCEDURE or EXECUTE FUNCTION. The two examples in the following figure show the structure of FOREACH loops.
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.
And yet another way would be to put a sequence container into your loop then put the conditional steps in the sequence container. Any decision that should 'continue' need only exit the sequence container. Very simple to implement with all the control you could want including error trapping.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With