Nested CASE WHEN Statement

I'm trying to figure out how to write a nested CASE WHEN statement but not sure how to do it exactly. I have 2 conditions that I need to look at.

CASE WHEN S.fstatus = 'Awaiting Approval' THEN S1.fprodcl ELSE CASE WHEN J1.WorkCenterName IS NULL THEN '04' As ELSE '01' END As NewProdCL

Does that look correct?? Basically its supposed to say IF S.fstatus = 'Awaiting Approval' Then S1.fprodcl and IF S.fstatus <> 'Awaiting Approval' THEN IF J1.WorkCenterName IS NULL THEN '04' ELSE '01'
LVL 1
Lawrence SalvucciInformation Technology ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Mike EghtebasDatabase and Application DeveloperCommented:
CASE S.fstatus
WHEN  'Awaiting Approval' THEN S1.fprodcl 
ELSE 
   CASE  J1.WorkCenterName
   WHEN  IS NULL THEN '04' 
   ELSE '01' 
   END 
End As NewProdCL

Open in new window

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
Lawrence SalvucciInformation Technology ManagerAuthor Commented:
Thank you again! I appreciate the quick responses!
Lawrence SalvucciInformation Technology ManagerAuthor Commented:
I'm actually getting an error message when I try to execute it. I'm getting the following errors:

Error in list of function arguments: 'IS' not recognized
Error in list of function arguments: ')' not recognized
Unable to parse query text.

Here is what I put in my query:

CASE S.fstatus
WHEN  'Awaiting Approval' THEN S1.fprodcl 
ELSE 
   CASE  J1.WorkCenterName
   WHEN  IS NULL THEN '04' 
   ELSE '01' 
   END 
End As NewProdCL

Open in new window

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Mike EghtebasDatabase and Application DeveloperCommented:
I am reading about the error
Mike EghtebasDatabase and Application DeveloperCommented:
change line 5 to:

WHEN  ISNULL(last_name, '')='' THEN '04'
                                                ^--^---- there 4 single quotes

CASE S.fstatus
WHEN  'Awaiting Approval' THEN S1.fprodcl 
ELSE 
   CASE  J1.WorkCenterName
   WHEN  ISNULL(last_name, '')='' THEN '04'
   ELSE '01' 
   END 
End As NewProdCL

Open in new window

Lawrence SalvucciInformation Technology ManagerAuthor Commented:
what is "last_name"? Is that supposed to be WorkCenterName?
Mike EghtebasDatabase and Application DeveloperCommented:
I must have messed it up. I am checking it now
Mike EghtebasDatabase and Application DeveloperCommented:
Sorry about it, try:

CASE S.fstatus
WHEN  'Awaiting Approval' THEN S1.fprodcl 
ELSE 
   CASE ISNULL( J1.WorkCenterName,'')
   WHEN '' THEN '04'
   ELSE '01' 
   END 
End As NewProdCL

Open in new window

Lawrence SalvucciInformation Technology ManagerAuthor Commented:
That worked! Thanks again!! Appreciate your help with the errors too!
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
It's better to use a different case syntax here.
CASE
   WHEN S.fstatus = 'Awaiting Approval' THEN S1.fprodcl 
   WHEN ISNULL( J1.WorkCenterName,'') = '' THEN '04'
   ELSE '01' 
END  As NewProdCL

Open in new window

because you then have only one level of conditions.
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.