Selection formula excluding rows with columns having null values

Walloud picture Walloud · Jun 12, 2013 · Viewed 9.2k times · Source

I have a strange issue. I have a report CR. In the Selection Formula I do a test on two fields. The test is simple like that : {field_City} = 'Paris' OR {field_Country} = 'France'.

This is a sample of the data in my table:

|---------------|---------------|---------------|
|   ID_Record   |    Country    |      City     |
|---------------|---------------|---------------|
|        1      |      null     |      Paris    |
|---------------|---------------|---------------|
|        2      |      France   |      null     |
|---------------|---------------|---------------|
|        3      |     France    |      Paris    |
|---------------|---------------|---------------|

The result of the Selection should be the 3 records, however it's excluding the 2 first rows where there is a null value in one of the columns. Then I changed the Selection Formula like this to consider null values too : ({field_City} = 'Paris' AND (isnull({field_Country}) OR not(isnull({field_Country})))) OR ({field_Country} = 'France' AND (isnull({field_City}) OR not(isnull({field_City})))) but I am still getting only the last record ! To ensure myself that my code is correct, I generated the sql query via the option in CR 'Show sql query', then i've added a WHERE clause in which I wrote the same condition that i've put in the Selection Formula, and...... it gave me the 3 records ! Unfortunately I can't work with the sql query, I have to find out why the formula is excluding the records that have a null value in one of the columns :( I hope that you can help me. Thanks a lot !

This is the solution: ((isnull({field_Country}) AND {field_City} = 'Paris') OR (isnull({field_City}) AND {field_Country} = 'France') OR (not(isnull({field_Country})) AND {field_City} = 'Paris') OR (not(isnull({field_City})) AND {field_Country} = 'France')) , Thank you so much Craig!

Answer

craig picture craig · Jun 12, 2013

You need to test for null values first:

( Not(Isnull({field_Country})) AND {field_Country}='France' )
OR
( Isnull({field_Country}) AND {field_City}='Paris' )