Sql Server 2000: How To Handle Null In Select Statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dhanashivam
    New Member
    • Mar 2007
    • 31

    #1

    Sql Server 2000: How To Handle Null In Select Statement

    Hi all,

    In my table there is a varchar column having NULL and string names.

    while i am running select on this table the NULL values are not returned. the statement returns only non null values. my query is

    SELECT EMP_ID, AGE FROM EMPLOYEE WHERE EMP_NAME <> 'BABU'

    in my table there is records with null values. but it retuns only non null values.

    thanks in advance,

    dhana.
  • davidson1
    New Member
    • Feb 2008
    • 144

    #2
    check like this...

    if isdbnull(emp_id )
    {
    Response.write( "Null Values")
    }
    else
    {
    Response.write( "Not Null Values")
    }

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Originally posted by dhanashivam
      Hi all,

      In my table there is a varchar column having NULL and string names.

      while i am running select on this table the NULL values are not returned. the statement returns only non null values. my query is

      SELECT EMP_ID, AGE FROM EMPLOYEE WHERE EMP_NAME <> 'BABU'

      in my table there is records with null values. but it retuns only non null values.

      thanks in advance,

      dhana.

      try:

      SELECT EMP_ID, AGE FROM EMPLOYEE WHERE EMP_NAME <> 'BABU' or EMP_NAME is NULL


      -- CK

      Comment

      • sonia.sardana
        New Member
        • Jul 2006
        • 95

        #4
        There is one exception with %. Not Even the clause where name like '%' will match a row with the value NULL.

        create table stu(name varchar(10))
        insert into stu values('sona')
        insert into stu values('soni')
        insert into stu values('sonia')
        insert into stu values(NULL)
        select * from stu
        select * from stu where name like '%'

        RESULT--

        sona
        soni
        sonia

        Comment

        • sonia.sardana
          New Member
          • Jul 2006
          • 95

          #5
          Hey Ck,the answer given by you was not working, SEE the EXAMPLE BELOW--
          create table student(roll int,marks int)
          insert into student values(1,10)
          insert into student values(2,10)
          insert into student values(3,20)
          insert into student values(4,NULL)
          select * from student
          select roll from student where marks <>20 AND marks is NULL

          RESULT--BLANK

          Comment

          • deric
            New Member
            • Dec 2007
            • 92

            #6
            Originally posted by sonia.sardana
            Hey Ck,the answer given by you was not working, SEE the EXAMPLE BELOW--
            create table student(roll int,marks int)
            insert into student values(1,10)
            insert into student values(2,10)
            insert into student values(3,20)
            insert into student values(4,NULL)
            select * from student
            select roll from student where marks <>20 AND marks is NULL

            RESULT--BLANK

            CK's example is correct. You should have used the "OR" operator, instead of "AND".

            Comment

            Working...