Answered != operator with NULL values

  • Donnerstag, 24. Januar 2013 04:19
     
     

    I'm  having a table like below.

    A        B

    1        1

    2        3

    3        3

    4        NULL

    5        NULL

    My condition is the records where A, B both not equal to 2.

    SELECT * FROM TAB WHERE A !=2 AND B !=2;

    If I give like this, record 4,5 are not retriving. NULL cann't be compared with values, but as per logic I need. I framed a complext query, its fine for 2, but for fields more than 2 its missarable. Help me with this.

Alle Antworten

  • Donnerstag, 24. Januar 2013 04:27
     
     Beantwortet

    SELECT * FROM TAB (case when A IS null then '' else a end) ! = 2 and   (case when b IS null then '' else b end) != 2

    I found this, but for NULL condition it won't be.

    SELECT * FROM TAB (case when A IS null then '' else a end) like '%' and   (case when b IS null then '' else b end) IS NULL

    • Als Antwort markiert Pasupathi Donnerstag, 24. Januar 2013 09:27
    • Tag als Antwort aufgehoben Pasupathi Donnerstag, 24. Januar 2013 09:28
    • Als Antwort markiert Pasupathi Donnerstag, 24. Januar 2013 10:42
    •  
  • Donnerstag, 24. Januar 2013 11:54
     
     
    you can use the function having, testing null, no???

    Fernando