5/05/2015

esProc Finds Differences between CSV files

userName and date are the logical primary key of both old.csv file and new.csv file, in which we want to find rows that are new, deleted and updated.


The source data is as follows:

As can be seen from the above data, in new.csv the 2nd and the 3rd row are the new and the 4th row is the updated; in old.csv the 3rd row is the deleted.
esProc code

A1,B1Retrieve the comma-separated files.

A2,B2Sort data by the key, as this is required by the following merge function.

A3Find the new records by the key. merge function is used to merge data sets. @d means calculating the difference during the merge. Similar options include @u for union and @i for intersection. The computed result is as follows:

A4Find the deleted records by the key. The computed result is as follows:

A5Take the key fields as ordinary ones to find the updated records. The computed result is as follows:


No comments:

Post a Comment