Select k.barcode+1 as missing From yourtable k; >> Where k.barcode+1 Not in (Select barcode From yourtable)>
*_______________________________________________________________________________ function GapsTest() create cursor barcode ; ( Id I ; ) insert into barcode values (1) insert into barcode values (2) insert into barcode values (3) insert into barcode values (25) insert into barcode values (37) =GapsFind('Barcode', 'Id') select GetGaps_MissingByRange browse nowait endfunc *_______________________________________________________________________________ function GapsFind(cursorname, fieldName) select NoNextId.&fieldName + 1 as IdFrom, ; min(T2.&fieldName) - 1 as IdTo ; from ; ( select &fieldName; from (m.cursorname) X; where ( not exists ; ( select * ; from ( ; select &fieldName - 1 as IdPrevious ; from (m.cursorname) ; ) IdPrevious ; where ( X .&fieldName= IdPrevious.IdPrevious ) ; ) ; ) ; and ( &fieldName<> ( select max(&fieldName) from (m.cursorname) ) ) ; ) NoNextId ; join (m.cursorname) T2 ; on ( NoNextId.&fieldName < T2.&fieldName) ; group by 1 ; into cursor GetGaps_MissingByRange nofilter ; order by 1 endfunc *_______________________________________________________________________________