Question : SQL CASE STATEMENT SYNTAX  HELP - SQL SERVER 2005

Hello experts,

I have a case statement here, and I am trying to embed a conditional and statement into it, and am not sure how to format the code.

I get the invalid syntax error of course on the first 'and' characters.

Thoughts? Thanks!

select
            CASE
            prescription_audit.operation_type  
             WHEN 'P' and pharmacy_mstr.name like '%mail order%' THEN '2'  -- for mail order
             WHEN 'P' and pharmacy_mstr.name not like '%mail order%' THEN '1'  -- for pharmacy
             WHEN 'E' THEN '0' -- for erx
             WHEN 'F' THEN '1' -- for fax
             ELSE '0'
            END AS Patient_Eligibility

from prescription_audit, pharmacy_mstr
where etc etc

Answer : SQL CASE STATEMENT SYNTAX  HELP - SQL SERVER 2005

select
            CASE WHEN prescription_audit.operation_type = 'P' AND pharmacy_mstr.name like '%mail order%' THEN '2'  -- for mail order
            WHEN prescription_audit.operation_type = 'P' and pharmacy_mstr.name not like '%mail order%' THEN '1'  -- for pharmacy
            WHEN prescription_audit.operation_type = 'E' THEN '0' -- for erx
            WHEN prescription_audit.operation_type = 'F' THEN '1' -- for fax
            ELSE '0'
           END AS Patient_Eligibility

from prescription_audit, pharmacy_mstr
where etc etc
Random Solutions  
 
programming4us programming4us