you have discovered sql's three-valued logic
with WHERE x NOT IN (subquery), if any of the subquery results are NULL then the condition evaluates UNKNOWN
example:
... WHERE x NOT IN ( 3, 4, NULL, 5 )
this is equivalent to
... WHERE NOT (x IN (3, 4, NULL, 5))
which is equivalent to
... WHERE ( (x<>3) and (x<>4) and (x<>NULL) and (x<>5) )
which is equivalent to
... WHERE ( (x<>3) and (x<>4) and UNKNOWN and (x<>5) )
which is equivalent to
... WHERE UNKNOWN
and hence no rows selected
to fix your problem, you should change
Code:
A.C_RELATIONSHIP_NO
NOT IN (
SELECT B.N_PORTFOLIO
FROM SB_X_COUNTY_PARATE B
WHERE B.C_CTL01 > 51
AND B.C_STATUS = 'ACT'
)
to
Code:
NOT EXISTS (
SELECT *
FROM SB_X_COUNTY_PARATE B
WHERE B.N_PORTFOLIO
= A.C_RELATIONSHIP_NO
and B.C_CTL01 > 51
AND B.C_STATUS = 'ACT'
)