Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Updating records in FoxPro tables
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00565010
Message ID:
00565083
Vues:
22
>>>>>I have some dupe records that are causing me problems and I need to delete one of the dupes for each record in several tables. Is there a way to do that without deleting each individual record by hand? Is there a way to do it using the command line?
>>>>
>>>>select KeyID, <b>recno() as RecNum</b>, count(*) as CntDups from yourtable group by KeyID ;
>>>>       having CntDups > 1 ;
>>>>       into cursor curDupes
>>>>index on KeyID tag KeyID
>>>>select yourtable
>>>>set relation to KeyID into curDupes
>>>>delete for found('curDupes') and recno()=curDupes.RecNum && One of the dupes would be deleted
>>>
>>>Unfortunately, this code would delete all duplicate records not just one of them.
>>
>>Oops, what I was thinking :) Ok, how about new version (see changes in bold)
>
>Sorry, not going to work eaither because RECNO() doesn't work properly with GROUP BY clause.

Ok, last try before I'll actually run a test :)
select KeyID, count(*) as CntDups from yourtable group by KeyID ;
       having CntDups > 1 ;
       into cursor curDupes
if _tally>0 && There are dups in table
  index on KeyID tag KeyID
  scan
  if seek(KeyID,'YourTable',"KeyID") && should be always found
     * select YourTable
     delete in YourTable && One duplicated record is deleted now
   endif
   endscan
endif
use in curDupes
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform