Results 1 to 2 of 2

Thread: compare null

  1. #1
    Join Date
    Jan 2012
    Posts
    2

    Unanswered: compare null

    Hi,

    I have to select all records from a table where some_flag column not equals 'Y'.

    the some_flag column value can be 'Y' or NULL.

    Code:
    select * from <table_name> where some_flag != 'Y'
    The query returns zero records.

    is it not possible to compare a NULL value ?

    I can perform an is NULL check like

    Code:
    select * from <table_name> where some_flag is NULL
    but not sure some_flag can have values other than Y or NULL (eg: 'N') later and I will lose those records with flag set to 'N'.

    is the below query the right way to do this ?

    Code:
    select * from <table_name> where some_flag != 'Y' or some_flag is NULL

  2. #2
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    COALESCE(some_flag, 'X') <> 'Y'
    Florin Aparaschivei
    DB2 9.7, 10.5 on Windows
    Iasi, Romania

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •