I have to concatenate 2 columns (ex. FIRSTANME and LASTNAME).
I do it this way:
FIRSTNAME || ' ' || LASTNAME`.
If one of them is null, but the other one is not null, I get null as concatenation result.
And I want following behavior
FIRSTNAME = null and LASTNAME = "Smith" ==>
FIRSTANME || ' ' || LASTNAME == ' Smith'.
How to solve this in DB2?
Use
coalesceOr using the
||concat operatorNote that IBM recomments using the keyword
concatand not the||operator.Concat: http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=%2Fcom.ibm.db2.doc.sqlref%2Ffconc.htm
Coalesce: http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=%2Fcom.ibm.db2.doc.sqlref%2Ffcoal.htm