Case not reacting to NULL's

  • How do you get your case statement to test for a NULL?

    SELECT CASE WHEN data1 = NULL OR data2 = NULL THEN NULL

    ELSE ... Nested Case....

    I have tried '' and NULL but I always fall through to the ELSE statement.

  • dwilliscp (7/13/2012)


    How do you get your case statement to test for a NULL?

    SELECT CASE WHEN data1 = NULL OR data2 = NULL THEN NULL

    ELSE ... Nested Case....

    I have tried '' and NULL but I always fall through to the ELSE statement.

    Try WHEN data1 is null OR data2 is null THEN null ELSE ...

  • Don't use =, use:

    data1 IS null

    null isn't a value, it's a state (the state of something with no value) , so equality will never return TRUE.

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • :w00t: :: David slaps his head:: Thanks for your help.

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

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