?
Solved

SQL Case When with embedded "or' conditions

Posted on 2015-01-11
2
Medium Priority
?
131 Views
Last Modified: 2015-01-11
I am trying to write a Case When statement with three conditions.  The first two are straight forward.  The third is a Case when with 4 or conditions:

Case when OE.Category = 'PHA' then
                                 case when P.DirectionID = '.STK-MED' then 
                                 [b]case when MOS.ProviderYn = 'Y' then 
                                      when MOS.CosignYn = 'Y' then 
                                      when OE.OrderDateTime = OEOS.SigDateTime then
                                      when DMU.ProviderID = OE.ProviderID[/b] then 1 else 0 end else 0 else 0 end as TotMedCPOE

Open in new window


As you see if the OE.Gategory = "PHA" and the P.DirectionID = '.STK-MED' no problem.  However the third condition can be anyone of 4 to be true.  What is the proper syntax for the last condition?

thanks Glen
0
Comment
Question by:GPSPOW
2 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 2000 total points
ID: 40543354
CASE WHEN MOS.ProivderYn = 'Y" or MOS.CosignYN = 'Y' or

etc.
0
 

Author Closing Comment

by:GPSPOW
ID: 40543365
Thank you
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

839 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