已答覆 null != value

  • Thursday, February 21, 2013 10:28 AM
     
     

    I have a table like

    ID         Name

    1           POP

    2           null

    3           Lop

    My query is select ID from tab where Name != 'POP'

    It should return 2,3. But it returns only 3.

    Logically 2nd record also should come. How to proceed that.

All Replies

  • Thursday, February 21, 2013 11:23 AM
     
     Answered Has Code

    Hi as null is not a value it cannot be compared using EQUALS operator.

    Wrap the Search argument up in an isnull i.e.

    select ID from tab where isnull(Name,0) !='POP'


    MCSA: (SQL 2012, SQL 2008, Windows Server 2008) MCITP: (SQL BI & SQL 2008) MCT: 2000 - 2013 www.lite-solutions.co.uk

    • Proposed As Answer by Lawrence A. Freeman Thursday, February 21, 2013 5:05 PM
    • Marked As Answer by Pasupathi Friday, February 22, 2013 4:35 AM
    •