locked
Including NULL in WHERE clause RRS feed

  • Question

  • How do include "IS NULL" in my WHERE clause along with a list of characters.

    So for example, the following fields should be include in the WHERE clause

    NULL
    Arts
    Science

    Currently im doing a UNION ALL, firstly getting all the NULLs and then all those with a normal character like Arts and Science

    Wednesday, April 17, 2013 12:49 PM

Answers

  • try this way :

    select * from 
    tablename where field is NULL OR field IN ('arts','science')


    Please vote if you find this posting was helpful or Mark it as answered.

    • Proposed as answer by Naomi N Wednesday, April 17, 2013 12:56 PM
    • Marked as answer by Sam233 Wednesday, April 17, 2013 1:14 PM
    Wednesday, April 17, 2013 12:51 PM

All replies

  • try this way :

    select * from 
    tablename where field is NULL OR field IN ('arts','science')


    Please vote if you find this posting was helpful or Mark it as answered.

    • Proposed as answer by Naomi N Wednesday, April 17, 2013 12:56 PM
    • Marked as answer by Sam233 Wednesday, April 17, 2013 1:14 PM
    Wednesday, April 17, 2013 12:51 PM
  • ive tried that initially and it doesn't pick up the NULLs with characters
    Wednesday, April 17, 2013 12:59 PM
  • You may try below if NULL is character NULL as well:

    select * from
    tablename where field is NULL OR field IN ('arts','science','NULL')



    Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    Wednesday, April 17, 2013 1:03 PM