首页 > 解决方案 > 在字符串字段的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。我尝试了一些东西,但没有任何效果。

标签: sqlreplacecase

解决方案


您可以使用

case when x = 0 then 12 else x end

推荐阅读