Skip to content
Advertisement

Relational Operators Issue With Null

I am having issues with the below select statement not picking up the data when I insert a relational operator.

If I remove the last line of the statement (A.PK_HIDE <> ‘Y’) it picks up the data I am expecting to see. The PK_HIDE column has only 3 different values in the column, ‘Y’, ‘N’ or Null. When removing the last line I pick up the data set where PK_HIDE = ‘N’.

I have also tried this statement:

That statement seems to ignore (A.CUSER7 = 'Y') as it pulls all data sets with A.PK_HIDE = 'N' OR A.PK_HIDE IS NULL.

Any help is appreciated. Thank you in advance.

Advertisement

Answer

If you want manage correctly null value in the first query you should use a NVL for PK_HIDE

In the second you must wrap the condition for PK_HIDE in ( )

if you dont’use ( A.PK_HIDE = 'N' OR A.PK_HIDE IS NULL) your where condition is equivalent to

that obviuosly produce the wrong result

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement