I have a requirement that I have to concatenate all the fields, and if any field is null then I have to give space.
For example:
-- 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
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
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments