• Simple. Add a loop continuation condition in your WHILE statement.

    [font="Courier New"]DECLARE @lb_Exit bit

    SET @lb_Exit = 0

    WHILE (@@FETCH_STATUS = 0) AND (@lb_Exit = 0) BEGIN

    IF your_condition SET @lb_Exit = 1

    END[/font]

    In fact, should @@ERROR become something else than 0 within the loop, I also use this method to exit the loop.