如何转换'零'作为CASE语句中的数值

时间:2017-02-24 17:58:56

标签: sql

我试图将[Per Occ Limit Between]的case语句中的零转换为数值,然后在满足以下条件时随[SIR Per Occ]一起添加。下面的代码工作正常,但我猜它是将值0视为字符串,并没有正确执行添加。如何正确转换,以便大小写条件取0作为数值。我正在使用SQL服务器

任何帮助将不胜感激!提前致谢。

     cast([SIR Per Occ] as float) * 1000000 as [SIR Per Occ],
     cast([SIR Agg] as float) * 1000000 as [SIR Agg],
     case when cast([Per Occ Limit Between] as float) is null
       then 0
       else
       cast([Per Occ Limit Between] as float) * 1000000 
       end as [Per Occ Limit Between],
     cast((cast([SIR Per Occ] as float)) + (cast([Per Occ Limit Between] as float)) as float) * 1000000 as [Policy Occ Attachment],

1 个答案:

答案 0 :(得分:2)

请改为尝试:

  [SIR Per Occ] = cast([SIR Per Occ] as float) * 1000000 
, [SIR Agg]     = cast([SIR Agg] as float) * 1000000 
, [Per Occ Limit Between] = coalesce(cast([Per Occ Limit Between] as float),0) * 1000000 
, [Policy Occ Attachment] = (cast([SIR Per Occ] as float) 
                          + coalesce(cast([Per Occ Limit Between] as float),0)) * 1000000