Page 1 of 1

Add "" within concat

Posted: Wed Apr 08, 2009 8:26 am
by papa
Hi,

Code: Select all

CONCAT_WS(' ', b.firstName, b.nickName, b.lastName)
Can I add a function within the concat which adds " " on b.nickName?

To get firstname "nick" lastname, and just not a separator between the names.

thanks!

edit:

And also if nickName == 0 it should not show. I guess that might not be possible in the query though.

Re: Add "" within concat

Posted: Thu Apr 09, 2009 5:33 am
by VladSun
[sql]CONCAT_WS(' ', b.firstName, IF(b.nickName=0, NULL, concat('"', b.nickName, '"')), b.lastName)[/sql]

It seems strange that b.nickName is string, but you check against integer value (0).
Maybe NULL is more appropriate.

Re: Add "" within concat

Posted: Thu Apr 09, 2009 10:03 am
by papa
Thanks once again!