SELECT Concat(mp.cHospital ,',',mp.cHospital1,',',mp.cHospital2) as Hospital FROM TBL
I dont want to return null value,
how to check not null or how to make isset cond in query
The CONCAT_WS() function adds two or more strings together with a separator.
The MySQL ISNULL() function is used for checking whether an expression is NULL or not. This function returns 1 if the expression passed is NULL, else it returns 0. The ISNULL() function accepts the expression as a parameter and returns an integer a value 0 or 1 depending on the parameter passed.
Both CONCAT() and CONCAT_WS() functions are used to concatenate two or more strings but the basic difference between them is that CONCAT_WS() function can do the concatenation along with a separator between strings, whereas in CONCAT() function there is no concept of the separator.
By definition (almost)any operation with NULL will result in NULL as NULL means "undfined". I interpret your question that either cHospital or cHospital1 or cHospital3 might be NULL which you want to check. The question is: what should happen? You want just the field replaced with an empty stirng and then the concat or all?
I assume the first. that might look like this:
SELECT Concat(
IFNULL(mp.cHospital, ''),
',',
IFNULL(mp.cHospital1,''),
',',
IFNULL(mp.cHospital2,'')) AS Hospital
FROM TBL
IFNULL returns the first part, unless its NULL where it returns the second part(empty string here).
http://dev.mysql.com/doc/refman/5.1/en/control-flow-functions.html#function_ifnull
I recommend using CONCAT_WS function. This works according to what you need. Would be something like
SELECT CONCAT_WS(',', mp.cHospital, mp.cHospital1, mp.cHospital2) as Hospital FROM TB
L
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat-ws
Greetings!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With