Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to find unused number in table
Message
From
07/05/2017 17:56:40
 
 
To
07/05/2017 15:48:55
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01650911
Message ID:
01650915
Views:
60
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 ?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform