Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to compare and update master table?
Message
De
04/05/2006 15:15:32
 
 
À
04/05/2006 14:52:12
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 7 SP1
OS:
Windows Server 2003
Divers
Thread ID:
01119103
Message ID:
01119335
Vues:
28
This message has been marked as a message which has helped to the initial question of the thread.
>I did your test. I got the same result as you. But I wonder about the presence of the "1 Val 1" in the final result? It's the same in both side, nothing different between test and test1 for this record. The union is not suppose to retain only the different records?

Ah, that was a logic error on my part. The UNION is doing exactly what it's supposed to do, that is eliminate DUPLICATE rows. You still get one of the rows (i.e. one of "1 Val 1") but not both of them. Try something like this:
* 1. Get rows that are present in both tables but have CHANGED.
* Same idea as before but add 2nd SELECT:
SELECT ;
  * ;
  FROM Master ;
  UNION ;
  SELECT ;
    * ;
    FROM Temp ;
  INTO CURSOR Crs1

SELECT ;
  PKey, ;
  COUNT(*) AS Cnt ;
  FROM Crs1 ;
  GROUP BY PKey ;
  HAVING Cnt > 1 ;
  INTO CURSOR Crs2

* The above yields a list of PKeys present in both tables but where rows are different

* 2. Get rows present in TEMP but not in MASTER:
SELECT ;
  * ;
  FROM Temp ;
  WHERE Temp.PKey NOT IN ;
    ( SELECT PKey FROM Master ) ;
  INTO CURSOR Crs3

* 3. Get rows present in MASTER but not in TEMP:
SELECT ;
  * ;
  FROM Master ;
  WHERE Master.PKey NOT IN ;
    ( SELECT PKey FROM Temp ) ;
  INTO CURSOR Crs4
There may be a more elegant way to do this in one SELECT but this should work for now.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform