Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to find unused number in table
Message
De
07/05/2017 17:56:40
 
 
À
07/05/2017 15:48:55
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01650911
Message ID:
01650915
Vues:
59
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 ?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform