I am trying to compare two tables, OldTable and NewTable that have a unique identifier of Pos_No and want to see if any of the other values have changes. The code is below. However, I am sometimes not getting the results I want. Specifically, I know it did not pick up a change in Act_end. The rest of the much larger series of statements works fine but just missing something that is probably obvious.

SELECT *FROM (SELECT [compareHR].[dbo].[TableOLD].[Pos_no], CHECKSUM(*) AS XSum FROM [compareHR].[dbo].[TableOLD]) AS OldFULL JOIN (SELECT [compareHR].[dbo].[TableNEW].[Pos_no], CHECKSUM(*) AS XSum FROM [compareHR].[dbo].[TableNEW]) AS NewWHERE Old.Pos_no IS NULL -- Row doesn't exist in old table OR New.Pos_no IS NULL -- Row doesn't exist in new table OR Old.XSum <> New.XSum; -- Row is different

Ah!! Right...and since we have so few nulls I didn't think of that...for now, I might just take the easy way out as I get the files in Excel and only a few fields can have null I will just replace with a "-" or something. Thanks for finding my oversight!

The issue could be related to the nullability of some of the columns. The are different ways to tackle this but using CHECKSUM is not one of them because the possibility for collision is high (it is not a good hashing function).

One way to accomplish this is using the INTERSECT operator. This operator treats NULL marks as equal so we can use something like:

Feel free to vote if you think this could make our life easier. The new query will look like:

SELECT A.c1, A.c2, A.c3, B.c2 AS B_c2, B.c3 AS B_c3FROM @T1 AS A INNER JOIN @T2 AS B ON B.c1 = A.c1WHERE (A.c2 IS DISTINCT FROM B.c2) OR (A.c3 is DISTINCT FROM B.c3)

The similar implementation as of today would be:

SELECT A.c1, A.c2, A.c3, B.c2 AS B_c2, B.c3 AS B_c3FROM @T1 AS A INNER JOIN @T2 AS B ON B.c1 = A.c1WHERE (A.c2 <> B.c2 OR (A.c2 IS NULL AND B.c2 IS NOT NULL) OR (A.c2 IS NOT NULL AND B.c2 IS NULL)) OR (A.c3 <> B.c3 OR (A.c3 IS NULL AND B.c3 IS NOT NULL) OR (A.c3 IS NOT NULL AND B.c3 IS NULL))GO

Yup, you nailed it hunchback .... the previous sheets I got did not have any nulls and I forgot that....just found out they only need this task to be done once a week for 2 sheets & I have to modify a few things in Excel to make it "SSIS friendly" so might just cheat with a dummy value that I know could never be used unless this becomes a bigger "project" and I have to do this 5 minute task often. Cheers all.-Dave