If these barcodes are to be used for commercial trade, you can't just pick any number since the number also contains a control digit. Other than that, this code will find "holes" in a series
Select k.barcode+1 as missing From yourtable k;
Where k.barcode+1 Not in (Select barcode From yourtable)
>table contains barcodes like
>
>create table barcode ( barcode n(7) )
>
>There are unused numbers in barcode column.
>How to find some free not used number in this table ?
>
>code
>
>
>function GetAvailableBarcode
>select max(barcode) as maxc from barcode into cursor maxc
>for i=1 to maxc-1
> sele barcode
> loca for barcode=i
> if !found()
> MessageBox('Free code'+ tran(i) )
> return i
> endif
> endfor
>messagebox('No free barcode')
>return maxc+1
>endfunc
>
>
>probably works but is probably slow since table contains thousands of codes.
>How to make this code faster ?
>Can some sql satement of index used ?