Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Re-numbering problem
Message
From
24/02/2009 12:27:45
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01383631
Message ID:
01383812
Views:
56
>Hi everybody,
>
>Can you please suggest an efficient algorithm of re-numbering? I have a table with the sequence number field (per each unique Fk). The sequence_number is supposed to be correct 1,2,3, etc., but we have data problem and some numbers are repeated.
>
>How can I re-number my records?
>
>Thanks in advance.

Before, fix duplicate foreignKey manually ... then
SELECT thetable
COUNT TO maxId
SET ORDER TO tag_sequenceField DESC
LOCATE
IF sequenceField > m.maxId
     maxId = sequenceField
ENDIF
* BEGIN TRAN
SCAN
  IF m.maxId <> sequenceField
       sequenceField = sequenceField
       replace sequenceField with m.maxId
       * update ... SET foreignkey = thetable.sequenceField WHERE  foreignkey = m.sequenceField
  ENDIF
  maxId = m.maxId - 1
ENDSCAN
* END TRAN
* if you want start with 1, now you can reprocess 
* in ascending and replace sequenceField 
SET ORDER TO tag_sequenceField ASC
SCAN
  IF sequenceField <> RECNO()
       sequenceField = sequenceField
       replace sequenceField with RECNO()
       * update ... SET foreignkey = thetable.sequenceField WHERE  foreignkey = m.sequenceField
  ENDIF
ENDSCAN
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform