Reputation: 5834
I have a table that contains 3 columns whose values can be null. I have to create a 4th column and concat value of only those columns that are not null. Expected Output:
col1 col2 col3 col4
----------------------------------------------------
1 0 1 col1=True;col2=False;col3=True;
0 Null 1 col1=False;col3=True
Upvotes: 1
Views: 31
Reputation: 1269643
Use concat_ws()
:
select concat_ws(';',
concat('col1=', elt(col1 + 1, 'false', 'true')),
concat('col2=', elt(col2 + 1, 'false', 'true')),
concat('col3=', elt(col3 + 1, 'false', 'true'))
)
from t;
Upvotes: 1
Reputation: 314
The simplest approach is to write a script in the language of you choice in order to update the existing data.
And then include this routine in your application.
Upvotes: 0