Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Looking for differences...
Message
From
27/11/2000 15:43:34
 
 
To
27/11/2000 14:56:04
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00445792
Message ID:
00445822
Views:
15
>I have two tables with identical structures and record counts. I need a quick way to extract the different rows from either table into a cursor or table. The differences might be a single field or more. Both tables have an integer PK and are in sync. Any thoughts? TIA

There might be commercial or shareware routines to accomplish this, but I don't know where they might be.

If you want to roll your own comparor in VFP, there are two main approaches you can take:

- loop through a list of your fields, and compare those field values for each record. This can tell you not only which records differ, but in which fields.

- convert each record to one or more character fields, and do a direct compare. This will point out differences, but not tell you which field(s).

If total record length (not counting the PK) is 254 or less, you could map the fields into a single character column:
SELECT ;
  CharField + STR(NumField) + DTOC(DateField) + ... AS CombinedField ;
  FROM MyTable1 ;
  INTO CURSOR MyCursor1

SELECT ;
  CharField + STR(NumField) + DTOC(DateField) + ... AS CombinedField ;
  FROM MyTable2 ;
  INTO CURSOR MyCursor2

GO TOP IN MyCursor2
SELECT MyCursor1
SCAN ALL
  IF MyCursor1.CombinedField == MyCursor2.CombinedField
    * Records are the same
    * Note exact comparator "==" used above

  ELSE
    * Records are different

  ENDIF

  SKIP IN MyCursor2

ENDSCAN
If your record length is over 254, map your fields into two or more character columns.
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform