CASE WHEN 2 Fields, 2 nulls

Probably an easy question but have a short deadline. I have two fields each with the a possibility of NULLS. I already did a case when but now realized that I may still have NULL values. How would I get rid of the final NULL if both fields are null. is it possible to nest inside an already created CASE WHEN?  
Here is my current Case When.

CASE WHEN fp2.ConfirmDate IS NULL THEN fp2.CommitDate ELSE fp2.ConfirmDate END
Southern_GentlemanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Give us a data mockup of what you're trying to pull off here.

>it possible to nest inside an already created CASE WHEN?  
Yes, here's an example (scroll half way down to 'CASE blocks can also be nested within themselves').

CASE
   WHEN fp2.ConfirmDate IS NULL THEN
       CASE WHEN fp2.CommitDate IS NULL THEN
              -- do both null here
       ELSE
              -- do only ConfirmDate is null here
       END
ELSE fp2.ConfirmDate END
0
Kent OlsenData Warehouse Architect / DBACommented:
Use coalesce.

  COALESCE (Date1, Date2, DefaultDate)

SQL will accept the first non-null item in the list.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Randy PooleCommented:
Select isNull(fp2.ConfirmDate,isNull(CommitDate,'2014-01-01')) 

Open in new window


 just replace 2014-01-01 with what you want is to be if both are null
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Aneesh RetnakaranDatabase AdministratorCommented:
nesting will work

CASE WHEN fp2.ConfirmDate IS NULL THEN fp2.CommitDate ELSE  
        case when fp2.ConfirmDate  is null then '' else  fp2.CommitDate  end END
0
sventhanCommented:
Here is how it works ...

Select Case NULL < === your fp2.confirmdate
  When NULL then 0 // Checks for NULL = NULL
  else 1 // NULL = NULL is not true end
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>How would I get rid of the final NULL if both fields are null.
Next time please do a better job in explaining your question, preferably with a data mockup of both before and after, so we don't have multiple experts assuming a lot of facts and providing different solutions.  Thanks in advance.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.