次のクエリがあります。
-- COLUMN SELECTION
-- INITIAL ENCOUNTERS
SELECT pt_no AS 'INITIAL ENCOUNTER'
, Episode_No AS 'INITIAL EPISODE NO'
, med_rec_no, pt_name AS 'PT NAME'
, adm_src_desc AS 'INITIAL ADM SOURCE'
, adm_date AS 'INITIAL ADM DATE'
, dsch_date AS 'INITIAL DISC DATE'
, DATEDIFF(DD,ADM_DATE,DSCH_DATE) AS 'INITIAL LOS'
, pyr1_co_plan_cd AS 'INITIAL INSURANCE'
, mdc_name AS 'INITIAL MDC'
, clasf_desc AS 'INITAL CLASF'
, Admit_Adm_Dr_Name AS 'INITIAL ADMIT DR'
, Admit_Atn_Dr_Name AS 'INITIAL ATTENDING'
, Days_To_Readmit
,
-- READMISSION ENCOUNTERS
B_Pt_No AS 'READMIT ENCOUNTER'
, B_Episode_No AS 'READMIT EPISODE NO'
, B_Adm_Src_Desc AS 'READMIT SOURCE'
, B_Adm_Date AS 'READMIT DATE'
, B_Dsch_Date AS 'READMIT DISC DATE'
, DATEDIFF(DD,B_ADM_DATE,B_DSCH_DATE) AS 'READMIT LOS'
, B_Pyr1_Co_Plan_Cd AS 'READMIT INSURANCE'
, B_Mdc_Name AS 'READMIT MDC'
, B_Clasf_Desc AS 'READMIT CLASF'
, B_Readm_Adm_Dr_Name AS 'READMIT ADMITTING DR'
, B_Readm_Atn_Dr_Name AS 'READMIT ATTENDING DR'
, B_Days_To_Readmit
-- DB USED
FROM smsdss.c_readmissions_v
-- FILTERS USED
WHERE adm_date BETWEEN '2012-05-01' AND '2013-04-30'
AND adm_src_desc != 'SCHEDULED ADMISSION'
AND pt_no < 20000000
AND B_Adm_Src_Desc != 'SCHEDULED ADMISSION'
AND B_Pt_No < 20000000
AND B_Dsch_Date IS NOT NULL
--AND pyr1_co_plan_cd IN (
--CASE WHEN pyr1_co_plan_cd = '*' THEN 'Self Pay'
-- ELSE pyr1_co_plan_cd
--END
--)
--AND B_Pyr1_Co_Plan_Cd IN (
--CASE WHEN B_Pyr1_Co_Plan_Cd = '*' THEN 'SELF PAY'
-- ELSE B_Pyr1_Co_Plan_Cd
--END
--)
結果pyr1_co_plan_cd
でB_pyr1_plan_cd
は、両方とも等しくなる可能性があります*
を強制的に次のようにCASE
するために、ステートメントを使用したいと思います。*
'Self Pay'
現在の CASE ステートメントの方法では、ケースを強制しようとしているアカウントが追い出されてしまいます。つまり、これらのケースは結果セットにヒットしなくなります。
ここに示すように、WHERE句でCASEステートメントを使用してみました
ありがとうございました