如何连接多列,当任何列具有空值时 [英] How to concatenate the multiple column,when anyone of the column is having null value
本文介绍了如何连接多列,当任何列具有空值时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个要求,我必须连接所有字段,如果有任何字段为空,那么我必须留出空间.
I have a requirement that I have to concatenate all the fields, and if any field is null then I have to give space.
例如:
-- If col1 value is not null
SELECT (YEAR||col1||(col2)) FROM table
-- output: 202112abc
-- If col1 value is null
SELECT (YEAR||col1||(col2)) FROM table
-- output : 2021 abc
任何人都可以帮助我我们如何做到这一点,我尝试了多种方法但它不起作用
Can anyone please help me how we can do that, I tried multiple ways but it's not working
推荐答案
您可以使用 when
删除空值或空字符串:
You can use when
to remove nulls or empty strings:
select (YEAR||case when col1 is null or col1 = '' then ' ' else col1 end||col2) from table
这篇关于如何连接多列,当任何列具有空值时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文