How to concatenate the multiple column,when anyone of the column is having null value

Abhishek

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

mck

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to concatenate the column,when one column is having null value

How to concatenate multiple dataframes having different column names and length

How to select rows having column value as null?

How to concatenate multiple csv files into one based on column names without having to type every column header in code

How to check whether column value is NULL or having DEFAULT value in Mysql

How do you concatenate multiple columns in a DataFrame into a another column when some values are null?

how to remove the column that having a null value with min and max

How to add in or concatenate a a value in another value in a column?

SAS: how to concatenate column b to column a when there are multiple rows per group in column a?

how to concatenate one column to another column when there is specific value in column in pandas

Concatenate column values of multiple rows based on another column value

How to concatenate two dfs having a similar datetime column?

How to concatenate rows with the same column value in python?

Concatenate multiple value from column into row without add some value

Highcharts: when having multiple columns for the same X axis value, how can I get 1 tooltip per column?

How to update multiple rows of multiple columns with single value having same condition for every column

How to check multiple columns for a value, but if the column is null then dont care about it

How to get records for a column having a value but not other

How to extract the json data from json array and also fetch the rows having json column value as null

Python - Concatenate multiple columns based on the value of each column

how to select a row from multiple rows with the same value in a column keep rows without null value in a column in R?

How to show a default value when a grid column value is null?

SQL : column having occasional NULL value inside AND clause

How to get the column for a column having max value in python?

how to convert column to row in mysql(column having the same value)

How to update column with null value

how to update column with null value?

How to concatenate multiple columns having n no of rows

Pivot category column having multiple corresponding value columns

TOP Ranking

HotTag

Archive