Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql concat when original field is empty

I'm trying to run CONCAT on a column with fields that may or may not be empty. If the field isn't empty, there is no problem, i.e. if field in coulmn A equals a:

SET A = CONCAT(A, '_b')

gives a_b. The problem is, if the field in column A is empty, the concat returns nothing. Is there a way for it to concatenate even if the field is empty, which, in this example, would return '_b'?

like image 542
n00b programmer Avatar asked Apr 13 '26 12:04

n00b programmer


1 Answers

In Sql server

SET A = CONCAT(isnull(A,''), '_b')

Use IFNULL in Mysql.

Refer different function as per different database

like image 179
Romil Kumar Jain Avatar answered Apr 16 '26 00:04

Romil Kumar Jain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!