• Thank you very much for your solution. However, I probably didn't explain clearly enough.

    The first sequence number doesn't necessarily start out with 1, it could start with 567891011 or what ever number

    but then it sequentially incremented so the next sequence number would be 567891012, etc...

    There is a first sequence number and last sequence number, for example: 567891011 to 567991011

    The logic for calculating firstorder, secondorder, and thirdorder is also based on the quantity (last sequence - first sequence)