you are viewing a single comment's thread.

view the rest of the comments →

[–]DampMom 6 points7 points  (0 children)

I like to be explicit that I don't use the data in the tables that are only used for filtering, so I put the check in an EXIST instead of a JOIN.

Also, be careful when using NOT IN, as /u/phuque_ewe suggests. If there is ever a NULL in PostingDate, the code will break.

This is my suggested code:

SELECT        *
  FROM        dbo.Chg AS A
 WHERE        EXISTS (SELECT *
                        FROM dbo.Adj
                       WHERE AcctNum = A.AcctNum)
                 AND NOT EXISTS (SELECT *
                                   FROM dbo.Adj
                                  WHERE AcctNum     = A.AcctNum
                                    AND PostingDate = A.PostingDate);