Check for NULL in CASE

Last post 05-19-2006 3:27 PM by cubeberg. 1 replies.

Sort Posts:

  • Check for NULL in CASE

    05-19-2006, 2:53 PM
    • Member
      298 point Member
    • sunstar
    • Member since 07-09-2004, 4:37 PM
    • BC, Canada
    • Posts 105
    SELECT whatever_field,
    CASE LEN(DrAccount)
      WHEN 12 THEN DrAccount
      ELSE CASE (Note1)
        WHEN NULL THEN Location + DrAccount
        ELSE Note1 + DrAccount
        END
      END AS Account
    FROM Table1

    The purpose of the CASE(Note1) is when Note1 column is null, return Location+DrAccount.

    The actual result is when Note1 column is null, it always returns null, Location+DrAccount is not executed. When Note1 column is not null, it returns correctly Note1+DrAccount.

    The problem seems to reside in validating the null value in
    WHEN NULL

    How to check for null in CASE(fieldname) WHEN ???
  • Re: Check for NULL in CASE

    05-19-2006, 3:27 PM
    • Member
      710 point Member
    • cubeberg
    • Member since 10-03-2005, 10:59 AM
    • Richmond, Virginia
    • Posts 142

    Have you considered using Coalesce?  Coalesce(Note1 + DrAccount, Location + DrAccount)

    COALESCE

    Returns the first nonnull expression among its arguments.

    Syntax

    COALESCE ( expression [ ,...n ] )

    Chris Berg, MCAD
    My Blog

Page 1 of 1 (2 items)