我有以下代码。 Case语句将列出的数字转换为文本,其余代码转换为NULL,但我不断收到以下错误:将VARCHAR VALUE'RDG5'转换为DATA TYPE INT时转换失败。 RDG5是转换为NULL的众多代码之一。有什么想法吗?
SELECT dbo.TACCPLI.SYS_EMP_ID_NR, MAX(dbo.TACCPLI.AML_TYP_CD) AS DEG, (CASE WHEN dbo.TACCPLI.AML_TYP_CD IN (20, 25)
THEN 'Associates' WHEN dbo.TACCPLI.AML_TYP_CD IN (30, 35) THEN 'Bachelors' WHEN dbo.TACCPLI.AML_TYP_CD IN (40, 45)
THEN 'Masters' WHEN dbo.TACCPLI.AML_TYP_CD IN (50) THEN 'PhD' ELSE NULL END) AS Degree_Level, dbo.TACCPLI.AML_TYP_CD
FROM dbo.TACCPLI RIGHT OUTER JOIN
(SELECT dbo.v_TMS_employee_HR.GEMSID, dbo.v_TMS_employee_HR.TMS_ID
FROM dbo.v_TMS_employee_HR INNER JOIN
dbo.v_sc17_TMS_Data_Career_Meeting_Rating ON
dbo.v_TMS_employee_HR.TMS_ID = dbo.v_sc17_TMS_Data_Career_Meeting_Rating.Employee_ID
WHERE (LEFT(dbo.v_sc17_TMS_Data_Career_Meeting_Rating.Meeting_Readiness_Rating, 2) IN ('14', '15')) AND
(dbo.v_TMS_employee_HR.Job_Group_Code >= '72') AND (dbo.v_TMS_employee_HR.Job_Group_Code <= '79') AND
(dbo.v_sc17_TMS_Data_Career_Meeting_Rating.Plan_Year = 2012) AND (dbo.v_TMS_employee_HR.Region NOT IN ('12', '13', '16', '17'))
GROUP BY dbo.v_sc17_TMS_Data_Career_Meeting_Rating.Meeting_Readiness_Rating, dbo.v_TMS_employee_HR.GEMSID, dbo.v_TMS_employee_HR.TMS_ID)
AS HPS ON dbo.TACCPLI.SYS_EMP_ID_NR = HPS.TMS_ID
GROUP BY dbo.TACCPLI.SYS_EMP_ID_NR, dbo.TACCPLI.AML_TYP_CD
答案 0 :(得分:1)
根据您的评论
嗯它正在尝试转换它,以便它可以执行case语句。不确定我是否喜欢它,对我来说它应该因为类型不匹配而无法解析它。
何哼哼
这是一个脆弱的令人讨厌的小屋,但是如果可以依赖AML_TYP_CD来保持它的最后两个字符是数字的那么
CASE WHEN Right(dbo.TACCPLI.AML_TYP_CD,2) IN ('20', '25')
可能是一种方法,但看到'20'和'25'等都有自己的含义,他们应该有自己的专栏。