I am trying to find a way to identify empty range of primary key.
I have a table that have for primary key only numbers, named id
.
I am trying to fill the gaps when receiving batch of products.
My column id
(primary) has numbers that can be following each other but for each product type we jump to another thousands and some employees are not following the rule of taking next free spot, they find an empty and use it!
I would need to find something that would have a functionality similar to:
select product.id
from product
where product.id >= x
and next product.id > x + y
- x would be the last used product
- y is the amount of product i have to fill in this batch.
For example; if x is my starting point and has a value of 25000 and y = 50, the first time 50 unused number is reach is from 26600 to 27500.
The result would give me 25999... which would be the last product entered.
It is mandatory that batch product have consecutive numbers.
Is there any query that can give that result?
thank you in advance!