0

我有以下查询:

-- 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_cdB_pyr1_plan_cd都可以等于*

我想使用一个CASE声明来强制*结果为'Self Pay'

我目前拥有 CASE 声明的方式最终会踢出我试图强制案例的帐户,这意味着这些案例不再影响我的结果集。

我确实尝试在 WHERE 子句中使用 CASE 语句,如此处所示

谢谢你

4

1 回答 1

2

这将改变在结果集中看到的方式而不改变结果集......

-- 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'
, CASE WHEN pyr1_co_plan_cd = '*' Then 'Self Pay' Else pyr1_co_plan_cd End 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'
, CASE WHEN B_pyr1_co_plan_cd = '*' Then 'Self Pay' Else B_pyr1_co_plan_cd End 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
于 2013-05-15T17:32:46.007 回答