Thursday, 30 August 2018

My sql query does not return a null value to non-status lines

My query is:

SELECT (SUM(credit)-SUM(debit)) AS balance
FROM member_transaction
WHERE member_id=" + mId + " AND reference_id NOT IN (
    SELECT user_reference_id FROM r_request WHERE status=7)

But it's not returning rows which has NULL in reference_id column. Is there anything wrong in my query?

Try to this
SELECT (SUM(credit) - SUM(debit)) AS balance
FROM member_transaction
WHERE member_id = " + mId + "
    AND isnull(reference_id, 0) NOT IN (
        SELECT user_reference_id
        FROM r_request
        WHERE STATUS = 7
        )

0 comments:

Post a Comment