• Another thing that works in order to find the gaps is to "interleave" the numbers together.

    Say you have a table where the ID field (works with date values too) is usually incremented, but could have gaps in it...

    select t1.id, t1.id+1 as nextval

    from t1 left outer join t2

    on t1.id = t2.id - 1

    where t2 is null

    I think I got this from one of JCelko's books.

    It of course doesn't help fill in the blanks in and of itself, but by providing the next number for the lowest number available to be filled, it definitely could be used in an application.

    The cartesian joins to generate the list of numbers is slick, though!!!