• Yes actually that is behavior I have seen as well when an aggregate is used in the query.

    In order to eliminate the NULL values you will need to group the data. If a GROUP BY is not used or check for NULL is not in where condition and will get unexpected results.

    select p.paynum, c.gcamount from #payment p

    cross APPLY(

    SELECT SUM(gcamount) gcamount

    FROM #certificate c

    WHERE c.paynum = p.paynum

    GROUP BY c.paynum

    )c