3

我有以下代码。Case 语句将列出的数字转换为文本,将其余代码转换为 NULL,但我不断收到以下错误: CONVERSION FAILED WHEN CONVERTING THE VARCHAR VALUE 'RDG5' TO 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
4

1 回答 1

1

根据您的评论

嗯,它正在尝试转换它,以便它可以执行 case 语句。不确定我是否喜欢这样,对我来说它应该只是因为类型不匹配而无法解析它。

嗬嗬

这是一个脆弱的讨厌的东西,但如果可以依赖 AML_TYP_CD 总是让它​​的最后两个字符是数字,那么

CASE WHEN Right(dbo.TACCPLI.AML_TYP_CD,2) IN ('20', '25')

可能是一种方法,但看到“20”和“25”等有自己的含义,他们应该有自己的专栏。

于 2013-01-11T22:23:13.073 回答