I'm working on a report that needs to return information from clients. If they have a policy #, then it needs to return their demographic information along with that #. If they do not have a policy number, then it needs to simply return their demographic info.
Currently, it "doubles up" on clients with Policy #s, returning two entries: one with a policy # and demographics, one simply with demographics.
here's what I have so far
SELECT DISTINCT
A.COMPANY
A.NOTES
B.PHONE
CASE WHEN C.TYPE = 'T' AND C.PRIMARY <> 'I' THEN (C.POLICY#) ELSE (NULL) END AS [POLICY]
Then I have some Joins, Where Clauses, and some Order by statements.
The problem is this: I want the distinct to return only distinct records, but the Case statement returns a clients results with either the C.Policy# OR as a Null value. Naturally, the DISTINCT clause sees this as two different clients (one with a policy# attached, one with a null value). I'm trying to get it so the clients with the NULL value simply dont show up.
Currently, it "doubles up" on clients with Policy #s, returning two entries: one with a policy # and demographics, one simply with demographics.
here's what I have so far
SELECT DISTINCT
A.COMPANY
A.NOTES
B.PHONE
CASE WHEN C.TYPE = 'T' AND C.PRIMARY <> 'I' THEN (C.POLICY#) ELSE (NULL) END AS [POLICY]
Then I have some Joins, Where Clauses, and some Order by statements.
The problem is this: I want the distinct to return only distinct records, but the Case statement returns a clients results with either the C.Policy# OR as a Null value. Naturally, the DISTINCT clause sees this as two different clients (one with a policy# attached, one with a null value). I'm trying to get it so the clients with the NULL value simply dont show up.