The following SQL allows me to find consecutive invoices on my database:
select inv.InvoiceId as StartInvoiceId, inv.InvoiceId + 49 as EndInvoiceId
from accounting.invoice as inv
where (inv.InvoiceId - 1) % 50 = 0
and 50 = (select count(*) from accounting.invoice
where invoiceId between inv.InvoiceId and inv.InvoiceId + 49)
order by inv.InvoiceId
You should be able to convert it to your needs.