我需要在SQL中重寫以下IF-THEN代碼,下面是我的第一次嘗試。但是當我運行SQL代碼時,它返回了一條錯誤消息:ORA-00933:SQL命令未正確結束。任何人都可以請幫忙?需要關於嵌套CASE語句的幫助
此外,我想知道是否有更好的替代方法來重寫SAS代碼,而不是使用嵌套的Case語句。我是SQL的新手。任何幫助將不勝感激!
/********************** SAS代碼****************** *****/
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;
/*********************** SQL代碼******* ****************/
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
;
不知道任何SAS,但它看起來像你的SQL缺少外部CASE。應該是「SET POS_new =」和「WHEN」之間的CASE。 – 2014-08-27 17:54:41