执行此SQL查询时,我收到以下区域消息:
关键字'else'
附近的语法不正确
以下是查询:
SELECT
*,
CASE
WHEN los IN (0, 1, 2, 3, 4) THEN 'under 5'
WHEN los >= 5 THEN 'above 5'
ELSE 'Unknown'
END AS los_type
FROM
(SELECT
CASE
WHEN LEN(comp.AGTNUMBER) = 6 THEN substring(comp.AGTNUMBER, 2, 5)
ELSE comp.AGTNUMBER
END AS FR_Number,
comp.COMPLAINTNUMBER,
YEAR(comp.opendate) AS Comp_Year,
comp.COMPLAINTORIGIN,
comp.COMPTYPE AS Comp_Type,
comp.OPENDATE,
comp.REBUTTAL,
comp.AGENTNAMEINCOM,
CASE
WHEN fr.FULL_TIME_SVC_DTE < comp.OPENDATE
THEN FLOOR(DATEDIFF(MONTH, fr.FULL_TIME_SVC_DTE, comp.OPENDATE) / 12)
WHEN fr.FULL_TIME_SVC_DTE > comp.OPENDATE
THEN floor(datediff(month, fr.ACTUAL_CONTRACT_END_DATE, fr.FULL_TIME_SVC_DTE) / 12
ELSE NULL
END AS los
FROM
dbo.EC_Complaints_Info AS comp
LEFT JOIN
dbo.FLD_REP_Info AS fr
ON CASE WHEN LEN(comp.AGTNUMBER) = 6
THEN substring(comp.AGTNUMBER, 2, 5)
ELSE comp.AGTNUMBER
END = fr.FR_NUMBER
AND comp.OPENDATE BETWEEN fr.ACTUAL_CONTRACT_START_DATE
AND fr.ACTUAL_CONTRACT_END_DATE
WHERE
((comp.REBUTTAL = 'No'))
AND ((comp.STATUS = 'open') OR
(comp.STATUS = 'closed'))
) AS a
任何人都可以帮我弄清楚为什么我收到此错误消息?
答案 0 :(得分:3)
您遗失了)
个CASE
表达式中的case when fr.FULL_TIME_SVC_DTE < comp.OPENDATE then floor(datediff(month, fr.FULL_TIME_SVC_DTE, comp.OPENDATE)/12)
when fr.FULL_TIME_SVC_DTE > comp.OPENDATE
then floor(datediff(month, fr.ACTUAL_CONTRACT_END_DATE, fr.FULL_TIME_SVC_DTE)/12 --here is the error
else null end as los
:
case when fr.FULL_TIME_SVC_DTE < comp.OPENDATE then floor(datediff(month, fr.FULL_TIME_SVC_DTE, comp.OPENDATE)/12)
when fr.FULL_TIME_SVC_DTE > comp.OPENDATE
then floor(datediff(month, fr.ACTUAL_CONTRACT_END_DATE, fr.FULL_TIME_SVC_DTE)/12)
else null end as los
应该是:
rabbitmq-server start
sbin/service rabbitmq-server start