sql case

Posted on 2008-11-20
Last Modified: 2012-05-05

I have the sql case statement below that works fine, however if the cn.disableReason is null then I want to return 'In-Active'

CASE candidateactive WHEN 1 THEN 'Active'  WHEN 0 THEN cn.disableReason  END  AS Status

Greatful for any help.

Question by:Soluga
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    CASE WHEN candidateactive  IS NULL THEN 'In-Active' WHEN candidateactive  = 1 THEN 'Active'  WHEN candidateactive  = 0 THEN cn.disableReason  END  AS Status
    LVL 1

    Author Comment

    Problem is if there is a null value in cn.diablereason then it overwrites 'in-active' with Null
    LVL 142

    Accepted Solution

    I see
    CASE WHEN candidateactive  IS NULL THEN 'In-Active' WHEN candidateactive  = 1 THEN 'Active'  WHEN candidateactive  = 0 THEN ISNULL( cn.disableReason, 'In-Active')  END  AS Status

    Open in new window

    LVL 1

    Author Closing Comment

    Excellent, thank very much.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
    Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video discusses moving either the default database or any database to a new volume.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now