找不到错误

时间:2013-01-22 20:14:32

标签: sql-server

我的代码是

    SELECT     dbo.COL_TBL_WAGES.[Job Group], SUM(CASE WHEN RRDD NOT LIKE '12%' AND RRDD NOT LIKE '13%' AND RRDD NOT LIKE '16%' AND RRDD NOT LIKE '17%' AND 
                      RRDD NOT LIKE '2706%' AND RRDD NOT LIKE '2707%' AND RRDD NOT LIKE '2331' THEN DUR_IN_HOURS ELSE 0 END) AS SP_DOM_HOURS, SUM(CASE WHEN RRDD NOT LIKE '12%' AND RRDD NOT LIKE '13%' AND RRDD NOT LIKE '16%' AND RRDD NOT LIKE '17%' AND RRDD NOT LIKE '2706%' AND RRDD NOT LIKE '2707%' AND RRDD NOT LIKE '2331%' THEN CAST([2011 Total] AS FLOAT)*CASE WHEN IsNumeric([DUR_IN_HOURS]) =1 THEN CAST([DUR_IN_HOURS] AS FLOAT) ELSE 0 END)) AS SP_DOM_COST
FROM         dbo.COL_v_STD_REP_FullCourseDetail INNER JOIN
                      dbo.COL_TBL_WAGES ON dbo.COL_v_STD_REP_FullCourseDetail.Job_Group_Code = dbo.COL_TBL_WAGES.[Job Group Code] INNER JOIN
                      dbo.COL_TBL_WAGES_INTL ON dbo.COL_TBL_WAGES.[Job Group Code] = dbo.COL_TBL_WAGES_INTL.[Job Group Code]

出现错误语法附近')'

1 个答案:

答案 0 :(得分:3)

您在第一个END上错过了CASE

 SUM(CASE 
        WHEN RRDD NOT LIKE '12%' 
            AND RRDD NOT LIKE '13%' 
            AND RRDD NOT LIKE '16%' 
            AND RRDD NOT LIKE '17%' 
            AND RRDD NOT LIKE '2706%' 
            AND RRDD NOT LIKE '2707%' 
            AND RRDD NOT LIKE '2331%' 
        THEN CAST([2011 Total] AS FLOAT) 
      END -- this is missing
    *
    CASE 
        WHEN IsNumeric([DUR_IN_HOURS]) =1 
        THEN CAST([DUR_IN_HOURS] AS FLOAT) 
        ELSE 0 END) AS SP_DOM_COST

您的完整查询将是:

SELECT dbo.COL_TBL_WAGES.[Job Group], 
    SUM(CASE 
            WHEN RRDD NOT LIKE '12%' 
                AND RRDD NOT LIKE '13%' 
                AND RRDD NOT LIKE '16%' 
                AND RRDD NOT LIKE '17%' 
                AND RRDD NOT LIKE '2706%' 
                AND RRDD NOT LIKE '2707%' 
                AND RRDD NOT LIKE '2331' 
            THEN DUR_IN_HOURS 
            ELSE 0 END) AS SP_DOM_HOURS, 
    SUM(CASE 
            WHEN RRDD NOT LIKE '12%' 
                AND RRDD NOT LIKE '13%' 
                AND RRDD NOT LIKE '16%' 
                AND RRDD NOT LIKE '17%' 
                AND RRDD NOT LIKE '2706%' 
                AND RRDD NOT LIKE '2707%' 
                AND RRDD NOT LIKE '2331%' 
            THEN CAST([2011 Total] AS FLOAT) END
        *
        CASE 
            WHEN IsNumeric([DUR_IN_HOURS]) =1 
            THEN CAST([DUR_IN_HOURS] AS FLOAT) 
            ELSE 0 END) AS SP_DOM_COST
FROM  dbo.COL_v_STD_REP_FullCourseDetail 
INNER JOIN dbo.COL_TBL_WAGES 
    ON dbo.COL_v_STD_REP_FullCourseDetail.Job_Group_Code = dbo.COL_TBL_WAGES.[Job Group Code] 
INNER JOIN dbo.COL_TBL_WAGES_INTL 
    ON dbo.COL_TBL_WAGES.[Job Group Code] = dbo.COL_TBL_WAGES_INTL.[Job Group Code]