Wednesday, March 21, 2012

Query filtering problem

I do not want results with combinations like this:

d.workphone is null and m.workphone = '0'

m.workphone is null and d.workphone = '0'

but my query below still brining in records like this, how can I fix this:

select m.number, m.workphone as master_workphone, d.workphone as debtor_workphone

FROM master m

INNER JOIN debtors d ON d.number = m.number

where (d.workphone <> m.workphone)
AND NOT (d.workphone = '' AND m.workphone = '')
AND NOT ((d.workphone = '0' AND m.workphone = '') OR (d.workphone = '' AND m.workphone = '0'))

Some thoughts...
You mention null as something you want to filter on, but your query does not filter on nulls, it only uses '' (empty string)

Could you provide some sample data that your query treats in the 'wrong' way and also what result you want from that example?

/Kenneth

|||sorry, I mean't ''|||

No problem, that's cool. =:o)

Can you provide with an example that your query does 'wrong'..?

A small script generating tables with just the necessary columns along with a few rows of data that illustrates your problem is enough.

/Kenneth

No comments:

Post a Comment