CASE仍然返回null

时间:2014-04-01 16:43:17

标签: sql sql-server null case

尝试获取Dx_3中的输出以打印'',如果它是NULL,但我尝试了所有内容(NULLIF()COALESCE()ELSE ''等)仍打印NULL

SELECT
    @RecordType AS RecordType_1
    ,AbstractData.AccountNumber AS AcctNum_2
    ,(SELECT
            CASE 
                    WHEN AD.Diagnosis IS NOT NULL THEN AD.Diagnosis
                    ELSE ''
            END
            FROM AbsDrgDiagnoses AD 
            WHERE (AD.DiagnosisSeqID ='1' AND AD.VisitID = AbstractData.VisitID)) AS Dx_3
FROM AbstractData --214
WHERE AbstractData.PtStatus <> 'REF'

1 个答案:

答案 0 :(得分:1)

SELECT @RecordType AS RecordType_1,
       AbstractData.AccountNumber AS AcctNum_2,
       COALESCE(AD.Diagnosis, '') AS Dx_3
FROM AbstractData
LEFT JOIN AbsDrgDiagnoses AD ON AD.VisitID = AbstractData.VisitID
WHERE AbstractData.PtStatus <> 'REF' AND AD.DiagnosisSeqID = '1'