我试图将这些 case 语句(CASE WHEN adj.adjcat = 'WRITE_OFF' THEN adj.amt)作为 'WriteOff' 添加到我的代码中,但在 ')' 错误附近出现了不正确的语法。消息 102,第 15 级,状态 1,第 18 行
我想要发生的是如果字段 adj.adjcat 是 write_off 然后将 adj.amt 中的值放入列 WriteOff 使用以下代码:
SELECT
ar.UCI
,ar.reportmonth
,(case when ar.transagebucket < 1 then '0_30'
when ar.transagebucket = 1 then '31_60'
when ar.transagebucket = 2 then '61_90'
when ar.transagebucket = 3 then '91_120'
when ar.transagebucket = 4 then '121_150'
when ar.transagebucket = 5 then '151_180'
else 'Over180' end) as AgeBucket
,ar.PatName as PatientName
,ar.AcctNu as AccountNumber
,Convert (varchar(10),ar.dos,101) as Svc_Date
,ar.cptdisplay
,(ins.insdesc+ ' - ' +ins.insmne) as Insurance
,Sum(ar.chgamt) as ChgAmt
,ISNULL(Sum(pmt.pmtamt),0) as PmtAmt
,(CASE WHEN adj.adjcat = 'WRITE_OFF' THEN adj.amt) as 'WriteOff'
,(CASE WHEN adj.adjcat = 'DEBIT' THEN adj.amt) as 'Debit'
,(CASE WHEN adj.adjcat = 'ADMIN_ADJ' THEN adj.amt) as 'AdminAdj'
,ISNULL((ar.curbal),0) as CurBal
FROM
rpt_dat_ARDetail ar
LEFT JOIN rpt_dat_PmtDetail pmt ON ar.clntid = pmt.clntid
AND ar.AcctNu = pmt.AcctNu
and ar.dos = pmt.dos and ar.reportmonth = pmt.reportmonth and ar.chgamt = pmt.chgamt
and ar.curbal = pmt.curbal
LEFT JOIN rpt_dat_AdjustmentDetail adj ON ar.clntid = adj.clntid
AND ar.aid = adj.aid AND ar.dos = adj.dos
INNER JOIN rpt_dic_Ins ins ON ar.insmne = ins.insmne AND ar.clntid = ins.clntid