1

我有我做过的最长的案例陈述,我无法解决这个错误。IT 说它附近有语法错误),我很尴尬,我无法弄清楚这么简单的错误

SUM(CASE 
      WHEN COL_V_STD_REP_FullCourseDetail.SYSTEM = 'GEMS' 
      THEN CASE 
             WHEN RRDD LIKE '12%' OR RRDD LIKE '13%' OR RRDD LIKE '16%' OR 
                  RRDD LIKE '17%' OR RRDD LIKE '2706%' OR RRDD LIKE '2707%' OR 
                  RRDD LIKE '2331%' 
             THEN [DUR_IN_Hours] 
             ELSE 0 
             END) AS SP_DOM_INTL_HRS
4

2 回答 2

6

你错过了第二个END

SUM(CASE 
      WHEN COL_V_STD_REP_FullCourseDetail.SYSTEM = 'GEMS' 
      THEN 
        CASE 
          WHEN RRDD LIKE '12%' 
            OR RRDD LIKE '13%' 
            OR RRDD LIKE '16%' 
            OR RRDD LIKE '17%' 
            OR RRDD LIKE '2706%' 
            OR RRDD LIKE '2707%' 
            OR RRDD LIKE '2331%' 
          THEN [DUR_IN_Hours] 
          ELSE 0 
        END
     END) AS SP_DOM_INTL_HRS
     ^ -- this is missing

顺便说一句,如果您格式化代码,您将更容易找到这些问题。

于 2013-01-24T19:43:21.763 回答
2

从逻辑上讲,当逻辑不那么复杂时,我不会嵌套 CASE 语句。对于这样的事情,我会在第一个 CASE 语句中添加嵌套 CASE 语句的逻辑(如下所示):

SUM(CASE 
  WHEN COL_V_STD_REP_FullCourseDetail.SYSTEM = 'GEMS' AND 
       (RRDD LIKE '12%' 
        OR RRDD LIKE '13%' 
        OR RRDD LIKE '16%' 
        OR RRDD LIKE '17%' 
        OR RRDD LIKE '2706%' 
        OR RRDD LIKE '2707%' 
        OR RRDD LIKE '2331%') THEN [DUR_IN_Hours] 
  ELSE 0 
END) AS SP_DOM_INTL_HRS
于 2013-01-24T19:52:34.873 回答