I tried with:
SELECT CONCAT(col1, col2) AS NewCol FROM tableName
It works only if col1 and col2 are not null, else NewCol becomes null, even if one of col1 and col2 is not null. I want it to display whatever value that is available.
Use CONCAT_WS
.
SELECT CONCAT_WS('', col1, col2) AS NewCol FROM tableName
It would return an empty string in case both the values are null
.
Documentation:
CONCAT_WS(separator,str1,str2,...)
CONCAT_WS() stands for Concatenate With Separator and is a special form of CONCAT(). The first argument is the separator for the rest of the arguments. The separator is added between the strings to be concatenated. The separator can be a string, as can the rest of the arguments. If the separator is NULL, the result is NULL.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments