Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Make field entry unique
Message
From
20/06/2021 19:46:18
John Ryan
Captain-Cooker Appreciation Society
Taumata Whakatangi ..., New Zealand
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01681459
Message ID:
01681460
Views:
52
Likes (1)
>>So some records have an ID that already exists. Other records have unique ID.
>>I want to run this table through a PRG and add a suffix '1', or '2', or '3' (depending on each duplicate record). So that the above table would look like this:

How about something along the lines of
select id_field,count(*) as cnt from mytable group by 1 order by 1 having cnt>1 into cursor c_fixme
SCAN
  licounter=0
  update mytable set id_field = rtrim(id_field)+mysuffix() where id_field=c_fixme.cid_field 
endscan

function mysuffix()
licounter=m.licounter+1
return transform(m.licounter)
"... They ne'er cared for us
yet: suffer us to famish, and their store-houses
crammed with grain; make edicts for usury, to
support usurers; repeal daily any wholesome act
established against the rich, and provide more
piercing statutes daily, to chain up and restrain
the poor. If the wars eat us not up, they will; and
there's all the love they bear us.
"
-- Shakespeare: Coriolanus, Act 1, scene 1
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform