• You just need to add one criteria to the CASE statement. Like this:

    [font="Courier New"]

    UPDATE #Counter2

    SET @Counter = Counter = CASE WHEN (@Counter >= 1 AND @Counter < 10) OR ([Value] >= 10 AND [Value] <=15 AND Code = 'a')

                               THEN @Counter + 1

                               ELSE 0 -- restart the counter

                               END

       ,@RowNumber = RowNumber

    FROM #Counter2

    [/font]