|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 9:55 AM
Points: 18,
Visits: 165
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, May 29, 2012 2:50 AM
Points: 190,
Visits: 88
|
|
The FULL OUTER JOIN method shown in the article has one major flaw compared to the EXCEPT method - identical rows are not excluded from the result set. With the example data provided it doesn't make a difference since the update ensures that there are differences in all rows - but in a real world example there will often be many identical rows and only a rather small number of differences to check (the last statement filtering out differences under a given tolerance only helps if it is possible to provide such a tolerance value - and it doesn't address the issue where a difference can occur in any number of fields.
The OUTER JOIN is still a good method to be able to compare source and destination tables - but I would combine it with the EXCEPT statement in order to only look at rows with actual differences.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 2:13 PM
Points: 5,237,
Visits: 7,044
|
|
But you can of course add a WHERE clause to exclude the identical rows (like the final example, where small differences were excluded - change the requirement to an exact match, and you get all differences, but no matching rows..
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, May 29, 2012 2:50 AM
Points: 190,
Visits: 88
|
|
| Agreed - however if the tables have a lot of fields instead, the where clause will be long and tedious to maintain.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 9:55 AM
Points: 18,
Visits: 165
|
|
It's not so bad to maintain. You just have to extend the WHERE clause:
WHERE ABS(RandomNumberDiff) > @Tolerance
to the following:
WHERE ( ABS(RandomNumberDiff) > @Tolerance OR ABS(RandomNumberDiff2) > @Tolerance OR ABS(RandomNumberDiff3) > @Tolerance ... )
to get the desired result. If you had 50 columns to compare, then it would make sense to generate this code using a query off INFORMATION_SCHEMA.COLUMNS.
This is definitely a real-world technique. We're using it at my company to compare 10's of thousands of rows across over 20 columns to reconcile datasets from disparate systems.
In the next chapter of this article I'll explain why it's useful to have the exact differences like this, and not just the identification of rows that are different from source to destination.
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Today @ 1:13 PM
Points: 3,578,
Visits: 5,119
|
|
Nicely written and detailed article. I like the mechanism too.
Best,
Kevin G. Boles SQL Server Consultant SQL MVP 2007-2012 TheSQLGuru at GMail
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Thursday, December 20, 2012 1:03 PM
Points: 265,
Visits: 589
|
|
| Nice solution that has great utility if extended to other data types with tolerances for dates, times, text, and binary values as well.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Wednesday, May 01, 2013 4:52 PM
Points: 1,379,
Visits: 2,626
|
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, May 01, 2013 1:33 PM
Points: 578,
Visits: 778
|
|
Good article though the Except part at the beginning seems superfluous and unnecessary. If you wanted to compare data sets to see variation then I don't know why an Except query would even come to mind. This seems like the next intuitive step to compare a data set after you have done an Except query and have determined there are records in your data set that do not match.
My nitpickyness (is that a word?) aside, this is a great article
Link to my blog http://notyelf.com/
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 9:55 AM
Points: 18,
Visits: 165
|
|
ShannonJk,
Thanks for the positive feedback, much appreciated!
I was just reviewing the EXCEPT query syntax at the top as it's the classic way to test for dataset deviations. I needed to set the context for situations where EXCEPT is appropriate before discussing where it's not.
In practice, if I were to run an EXCEPT query in some of the situations that I use the FULL JOIN, it would return many thousands of rows, with miniscule deviations. I can safely assume that the two datasets in these situations will never match exactly, which is why I go directly to the FULL JOIN technique to find the exact deviations.
-Mark
|
|
|
|