-3

我正在尝试使用以下代码组合案例语句并不断遇到错误。

SELECT     
        dbo.COL_TBL_WAGES.[Job Group], 
        SUM(CASE
                 WHEN COL_V_COST.EMP_TNG_RL_CD = 'ST' 
                  THEN ([CountOfEMP_TNG_STT_DT] * 
                      (WHEN IsNumeric([TBL_VCOURSE.Length]) 
                        THEN TBL_VCOURSE ELSE 0 END) AS ST_Hours
4

1 回答 1

2

看起来您想要这个,因为您CASE的原始表达式中有两个表达式:

SELECT  dbo.COL_TBL_WAGES.[Job Group], 
    SUM(CASE 
            WHEN COL_V_COST.EMP_TNG_RL_CD = 'ST' 
            THEN [CountOfEMP_TNG_STT_DT] 
            ELSE 0 END
        * CASE 
            WHEN IsNumeric([TBL_VCOURSE.Length]) = 1 
            THEN TBL_VCOURSE 
            ELSE 0 END
        ) AS ST_Hours

编辑,根据您的评论,您的查询将与此类似:

SELECT dbo.COL_TBL_WAGES.[Job Group], 
    SUM(CASE 
            WHEN COL_V_COST.EMP_TNG_RL_CD = 'ST' 
            THEN [CountOfEMP_TNG_STT_DT] ELSE 0 END 
        * CASE 
            WHEN IsNumeric([COL_TBL_VCOURSE].[Length]) = 1 
            THEN COL_TBL_VCOURSE.[LENGTH]
            ELSE 0 END) AS ST_Hours, 
    SUM(CASE 
            WHEN COL_V_COST.EMP_TNG_RL_CD = 'ST' 
            THEN [CountOfEMP_TNG_STT_DT]*CAST([2011 Total] AS FLOAT) ELSE 0 END 
            * CASE 
                WHEN IsNumeric([COL_TBL_VCOURSE].[LENGTH]) = 1 
                THEN CAST([COL_TBL_VCOURSE].[LENGTH] AS FLOAT) ELSE 0 END) AS ST_Cost
于 2013-01-22T15:33:51.140 回答