Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case within a Case Statement

Status
Not open for further replies.

luvmy2Js

IS-IT--Management
Sep 1, 2010
43
US
Is there anyway to correctly write a SQL statement for a case statment within a case statement? Below is what I have and it is not working:

'Task' =
CASE WHEN
(
CASE
WHEN NOT ia.[EmployeeGroup] IS NULL THEN ia.[EmployeeGroup]
ELSE ec.[Employee Type]
END) = 'Contractor' then 'Contractor' else 'Hire Employee' End,
 
Code:
CASE WHEN COALESCE(ia.[EmployeeGroup]
                  ,ec.[Employee Type]) = 'Contractor' 
     THEN 'Contractor' 
     ELSE 'Hire Employee' END  AS Task
:)

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Below is what I have and it is not working

Can you please elaborate? Are you getting an error? If so, what is the error message? Are you getting incorrect results?

By the way... you don't really need to use nested case statements here.

If I understand the logic correctly, the follow code snippet should work for you.

Code:
'Task' = Case When Coalesce(ia.[EmployeeGroup], ec.[Employee Type]) = 'Contractor' Then 'Contractor' Else 'Hire Employee' End,

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Sorry Rudy.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
WOW~ don't know what I was thinking? Thanks for the clarity. You guys really help me out more than you will ever know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top