sql - 在字符串字段的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
推荐阅读
- html - 在 Blazor 中返回字符串
- python - 多次更新 shapefile 中的数据
- common-lisp - 在符号列表上调用 print-object
- jquery - 如何选择任何类型(文本、单选、复选框)的所有输入元素?
- c++ - 我可以按值重新排序地图中的元素吗?C++
- ruby-on-rails - 在 UI 模式下在 Github 操作中运行 Capybara 测试
- r - 将字符串作为文字传递以创建图形对象
- c# - ASP.NET Core MVC 修改实体导致 NullReferenceException
- android - 如何在android的edittext中使第一个字符为数字,第二个字符为字母?
- azure - kubernetes 500内部服务器故障排除