How to break out of For Each Loop

  • I have a package that uses a For Each Loop ( For Each File enumerator ) to import all the files in a directory into my database.  I want to be able to set a configurable value that will limit how many files will be imported at a time.  How can I best modify my package to break out of the loop when I reach my configured number of files?  I don't want to end the package, I just want to break out of the loop. 

  • You could use a while loop and a counter something like

    DECLARE @counter1 int

    DECLARE @total_count1 int

    SET @counter1 = 1

    SET @total_count1 = N

    WHILE @counter1 < = @total_count1

    BEGIN

    "CODE HERE"

    SET @counter1 = (@counter1 + 1)

    END

    I hope this helps,

    jim

  • The problem lies in the For Each File Loop.  I don't see how I can implement any kind of counter without ditching my existing For Each File loop.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply