Retrieving Null Values

  • Question in review today is Creating a Report showing the FName, LName of all Employees not Specified in a region; I would assume "No Value to be Null" Correct?

    Or is there another way for me to do this?

    This is what I have so far...What am I missing that this is not showing me results?

    Select Firstname, Lastname, Region

    From Employees

    WHERE Region LIKE 'null%';

    Thank you for your help.

  • Your query will only return rows where the region starts by null, which is different from a NULL value.

    To compare NULL values, you need to use IS NULL or IS NOT NULL. That's different from something = NULL which will never evaluate to true.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Luis Cazares (9/10/2015)


    Your query will only return rows where the region starts by null, which is different from a NULL value.

    To compare NULL values, you need to use IS NULL or IS NOT NULL. That's different from something = NULL which will never evaluate to true.

    Never? Try setting ANSI NULLS to OFF and then trying it. NB: I do not recommend setting ANSI NULLS to OFF in general, and at some unspecified point in the future, that option will no longer be available.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Try this...

    Select Firstname, Lastname, isnull(Region,'')

    From Employees

    WHERE Region = ''

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply