Missing numbers

  • I have an smallint field which can have maximum of 6000 value.

    Everytime I insert record I want to insert the next available number but not the max(field1) + 1.

    Because I might be deleting some records so there would be some unused numbers between 1 - 6000 which were not allocated yet.

    Is there any single command or I have to use cursor and check out the next value with previous value.

  • Hello saama5,

    This should return the lowest key that does not have a consecutive key:

    SELECT MIN(keyName)

    FROM tableName

    where keyName <plus sign> 1 NOT IN

    (SELECT keyName FROM tableName)

    (In the third line between 'keyName' and '1', please insert the single character plus sign. It is not showing up in my preview, so I assume it will not show up in the posting either. I don't know the trick to get around this. Sorry)

    Jennifer

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply