SQL - Syntax error when using multiple Case When conditions

I have a SQL report that I have added  Case When statements to.  When I run the report I get a Syntax Error near "OR" in statement.  Can you see why:

      CASE WHEN ((RAQ_R1.Query_MisQryID = 'PNRASPV' AND RAQ_R1.ValueInfo = 'Y') AND  
             (RAQ_R1.Query_MisQryID = 'PNRRESHE' AND RAQ_R1.ValueInfo = 'Tracheostomy') AND
             (RAQ_R1.Query_MisQryID = 'PNRSTCO' AND RAQ_R1.ValueInfo = 'N') AND
             (RAQ_R1.Query_MisQryID = 'PNRHXCVA01' AND RAQ_R1.ValueInfo = 'Y')) AND OO_M2.Procedure_OmOrdDictID = 'SEC.ST.RAD.BMH'
             THEN 'Yes' OR
             ((RAQ_R1.Query_MisQryID = 'PNRASPV' AND RAQ_R1.ValueInfo = 'Y') AND
             (RAQ_R1.Query_MisQryID = 'PNRRESHE' AND RAQ_R1.ValueInfo = 'Tracheostomy') AND
             (RAQ_R1.Query_MisQryID = 'PNRSTCO' AND RAQ_R1.ValueInfo = 'N') AND
             (RAQ_R1.Query_MisQryID = 'PNRHXCVA01' AND RAQ_R1.ValueInfo = 'Y')) AND OO_M2.Procedure_OmOrdDictID <> 'SEC.ST.RAD.BMH'
             THEN 'No' END AS 'Order Placed'
      

KR
kvrogersAsked:
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.

Scott PletcherSenior DBACommented:
Yes I can.

You need to start a WHEN to apply the next set of conditions:

   THEN 'Yes' --OR   --<<-- remove the OR
WHEN  --add the WHEN
   ((RAQ_R1.Query_MisQryID = 'PNRASPV' AND RAQ_R1.ValueInfo = 'Y') AND
kvrogersAuthor Commented:
So the outcome of this is she wants to know  Yes an order was placed or No an order was not placed.  The only difference between the two CASE WHEN  statements is in the last line of the second CASE WHEN, where the OmOrdDictID is NOT EQUAL 'SEC.ST.RAD.BMH'

I entered your suggestion above :  
THEN 'Yes'
            WHEN ((RAQ_R1.Query_MisQryID = 'PNRASPV' AND RAQ_R1.ValueInfo = 'Y') AND
             (RAQ_R1.Query_MisQryID = 'PNRRESHE' AND RAQ_R1.ValueInfo = 'Tracheostomy') AND
             (RAQ_R1.Query_MisQryID = 'PNRSTCO' AND RAQ_R1.ValueInfo = 'N') AND
             (RAQ_R1.Query_MisQryID = 'PNRHXCVA01' AND RAQ_R1.ValueInfo = 'Y')) AND OO_M2.Procedure_OmOrdDictID <> 'SEC.ST.RAD.BMH'
             THEN 'No' END AS 'Order Placed'

and in the report my column "Order Placed" it says NULL.  I would like it to say Yes (an order was placed) or NO (an order was not placed.

KR
Scott PletcherSenior DBACommented:
THEN 'Yes'
ELSE 'No' END AS 'Order Placed'

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
kvrogersAuthor Commented:
Very Helpful.
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.