1

我有一个Case When工作正常的声明:

sum(CASE WHEN datepart(dw,applydtm) = '1'
         then (cast(durationsecsqty as float)/3600)
         else 0
     End
   ) as Sunday

WHEN但是当它到达时我需要添加另一个(cast(durationsecsqty as float)/3600)。此时如果返回结果是0我想从另一列中提取值,moneyamt.

我正在尝试将此声明与我的第一个声明结合起来:

Case (CAST(durationsecsqty as float)/3600)
     when 0
     then moneyamt
     else (CAST(durationsecsqty as float)/3600)
 end as Sunday 
4

1 回答 1

2

听起来你需要这个:

sum(
    CASE 
        WHEN datepart(dw,applydtm) = '1' 
        then 
            CASE
                WHEN Case (CAST(durationsecsqty as float)/3600) = 0
                THEN moneyamt
                ELSE (CAST(durationsecsqty as float)/3600)
            END (cast(durationsecsqty as float)/3600) 
        else 0 
   End) as Sunday
于 2012-07-26T15:06:08.890 回答