我試圖添加這些case語句(CASE WHEN adj.adjcat ='WRITE_OFF'THEN adj.amt)作爲'WriteOff'給我的代碼我得到一個不正確的sytax附近')'錯誤。 消息102,級別15,狀態1,行18'='附近的語法錯誤錯誤CASE語句
如果字段adj.adjcat然後write_off把值從adj.amt列覈銷 用下面的代碼我希望發生的是:
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
您錯過了'end'或'else end' –