在 case 语句结果中的一个字段中替换 0,该字段是字符串字段



我有一个如下语句:

select distinct s.field1, s.field 2, 
Case when s.intfield3 = 2018 then (RTRIM(cast(s.intfield4 as char (2))) +'/1/'+ cast(s.intfield3 as char (4)))
when c.intfield3 = 2018 then (RTRIM(cast(c.intfield4 as char(2))) +'/1/'+ cast(c.intfield3 as char (4)))
End as newfield

我的问题是 s.intfield4 和 c.intfield4 有一些 0 个值。 我需要将这些 0 值更改为 12。 我已经尝试了一些方法,但没有任何效果。

您可以使用

case when x = 0 then 12 else x end

最新更新