Information générale
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Replace not working!! ahhhhhhh!!!!
:) Good morning all. I have a question...I have a field in a table that is numeric, and is incremented by 1 for each record. The table is a list of items. Each item must have a unique number. I would like to run a SCAN statement to update the entire table (3000 records) with an auto-incrementing number for each record. here's my code:
LOCAL ln_cnt
ln_cnt = 100001
SELECT 0
USE tablename AGAIN ALIAS x_tablename
SELECT item, uniqnum from x_tablename order by uniqnum into cursor c_items
SELECT c_items
GO TOP
SCAN
SELECT x_tablename
LOCATE FOR ;
item = c_items.item
IF FOUND()
REPLACE x_tablename.uniqnum WITH ln_cnt
ln_cnt = ln_cnt + 1
ELSE
MESSAGEBOX("Item not found.")
ENDIF
ENDSCAN
******************************************8
when it gets done...each record should have a unique number beginning with 100001 (in theory :). however, when i go back to check my table, it has only updated the first record, and nothing else has happened. i run the entire code again, and this time it updates 2 records. i run the entire code again, and it updates another record, however, it duplicates the number. so i have 3 records updated with numbers of 100001, 100002, 100003. and the rest of the table is the same. any clues??? TIA
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement