When it is necessary to compare the two tables and find the exceptional lines, and the difference can be any of the columns, there are 2 commands (do not exist in mssql2000) that make it easier:
EXCEPT - Compare the 2 tabales and return the existing values in the first table, but not in the second table.
INTERSECT - Compare the 2 tabales and return only the shared values.
Note: like UNION, the tables for comparison should have the same structure - same columns, same data-types.
SELECT PartId, CutQtyRatio FROM @FirstMixer
EXCEPT
SELECT PartId, CutQtyRatio FROM @NextMixer
SELECT PartId, CutQtyRatio FROM @FirstMixer
INTERSECT
SELECT PartId, CutQtyRatio FROM @NextMixer
INTERSECT
SELECT PartId, CutQtyRatio FROM @NextMixer
No comments:
Post a Comment