title: Need Help on Nested CASE statement
body: <p>I need to rewrite the following IF-THEN code in SQL, and below is my first attempt. But when I ran the SQL code, it returned an error message of : ORA-00933: SQL command not properly ended. Could anyone please help? </p>
  
  <p>And also, I am wondering if there is a better alternative way to rewrite the SAS code other than using a nested Case statement. I am a newbie to SQL. Any help will be greatly appreciated!</p>
  
  <p>/<strong>**********************</strong> SAS code <strong>***********************</strong> /</p>
  
  <pre><code>if Record_type = 'Cliam'and Claim_Type_E0141 in ('C','H','M','F','I','N','K','Z') THEN DO;
  if POS in ('21','22','23','24','25','26','27','28') then POS_new=31;
  if POS in ('86') then POS_new=32;
  if POS in ('81','82') then POS_new=34;
  ('61','62','63','64','65','66','67','68') then POS_new=54;
  END;
  
  if Record_type = 'Encounter'and ENCOUNTER_TYPE_H054 in ('I') THEN DO;
  if BILL_TYPE_CODE_1_2 in ('21','22','23','24','25','26','27','28') then POS_new=31;
  if BILL_TYPE_CODE_1_2 in ('86') then POS_new=32;
  if BILL_TYPE_CODE_1_2 in ('81','82') then POS_new=34;
  if BILL_TYPE_CODE_1_2 in ('61','62','63','64','65','66','67','68') then POS_new=54;
  END;
  </code></pre>
  
  <p>/<strong>***********************</strong>   SQL code <strong>***********************</strong> /</p>
  
  <pre><code>UPDATE ALL_INPT
  SET POS_new = 
       WHEN Record_type = "Claim" and Claim_Type_E0141 in ('C','H','M','F','I','N','K','Z')
            THEN CASE 
                  WHEN POS in ('21','22','23','24','25','26','27','28')
                         THEN '31' 
                  WHEN POS in ('86')
                         THEN '32' 
                  WHEN POS in ('81','82')
                         THEN '34' 
                  WHEN POS in ('61','62','63','64','65','66','67','68')
                         THEN '54' 
                  ELSE POS
             END 
  
       WHEN Record_type = "Encounter" and ENCOUNTER_TYPE_H054in ('I')
            THEN CASE 
                  WHEN BILL_TYPE_1_2_E0394 in ('21','22','23','24','25','26','27','28')
                         THEN '31' 
                  WHEN BILL_TYPE_1_2_E0394 in ('86')
                         THEN '32' 
                  WHEN BILL_TYPE_1_2_E0394 in ('81','82')
                         THEN '34' 
                  WHEN BILL_TYPE_1_2_E0394 in ('61','62','63','64','65','66','67','68')
                         THEN '54'
                  ELSE  BILL_TYPE_1_2_E0394
             END                  
  END
  </code></pre>
  
  <p>;</p>