Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Comparing Data
Message
De
16/11/2001 06:10:41
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
15/11/2001 19:08:23
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00582466
Message ID:
00582633
Vues:
27
>Hi All,
> I have one table (table A) that has the data I want to compare with another table (table B). I was thinking of using the scatter memvar command in table A and scanning through table B. If there were records that I had missed or were unique I would append them into table A from table B. Has anyone done this before? Is there a better way to compare data in two tables?
>Thanks,

Winn,
There is no one easy way to do it (or I don't know:). Strategy greatly depends on your tables (have primary key id or not, one or more fields define a unique id or not, has general field that also contributes to check or not etc).
Assuming it's quite generic data (no key or combination of fields that make up a unique record) :
select * from tableA ;
union ;
select * from tableB ;
into cursor AllInOne nofilter && AllInOne has unique records
If you had a pimary key and you only want to append tableB recs not in tableA :
select * from tableB ;
 where PKID not in ;
 (select PKID from tableA) ;
 into cursor crsNewRecs nofilter
select tableA
append from dbf('crsNewRecs')
And another approach with scatter-gather assuming PKID exists and if PKID match but content different (no general field check) than tableB record takes precedence and getting data from tableB to A (instead of PKID a unique record might be identified by combined fields):
local loRecA,loRecB
select tableB
scan
 scatter name loRecB memo
 select TableA
 if !seek(tableB.PKID,'tableA','PKIDTag') && New
  append blank
  gather name loRecB memo
 else
  scatter name loRecA memo
  if !compobj(loRecA,loRecB) && If mismatch
     gather name loRecB memo && TableB takes precedence 
                             && (might be based on a timestamp check)
  else && Nothing here-match
  endif
 endif
 select TableB && Not needed really but I'm paranoid:)
endscan
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform