zohab Posted February 7, 2012 Share Posted February 7, 2012 Hi, I am able to concat 3 fields using following command but if any field is empty or null then I am not getting concate string. I am getting empty string. SELECT CONCAT(account.phone_country_code,'-',account.phone_city_code,'-',account.phone) AS phone FROM account I try for CONCAT_WS from MYSQL documentation but not able to achibe result. http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat-ws Any solution for this problem? -Thanks Quote Link to comment Share on other sites More sharing options...
fenway Posted February 7, 2012 Share Posted February 7, 2012 SELECT CONCAT_WS('-', account.phone_country_code, account.phone_city_code, account.phone) AS phone FROM account As an added benefit, CONCAT_WS is happy to ignore NULLs -- unlike CONCAT, which barfs. Quote Link to comment Share on other sites More sharing options...
kickstart Posted February 7, 2012 Share Posted February 7, 2012 Hi What is the problem you are having with it? SELECT CONCAT_WS('-',account.phone_country_code,account.phone_city_code,account.phone) AS phone FROM account Or is it that blank columns are skipped on a row? If so use IFNULL on each column. All the best Keith Quote Link to comment Share on other sites More sharing options...
zohab Posted February 9, 2012 Author Share Posted February 9, 2012 Thanks. I am getting result but if column in empty then I am getting separator in string like following. ----123-123456 ---123-123456 --123-123456 It is possible not to include column and separator if column in empty? - Thanks. -123-123456 Quote Link to comment Share on other sites More sharing options...
kickstart Posted February 9, 2012 Share Posted February 9, 2012 Hi Think that is the default behavior for NULL values, which suggests that the columns are blank rather than NULL. All the best Keith Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.