|
Posted by Toby A Inkster on 04/30/07 10:24
Bruce A. Julseth wrote:
> SELECT CONCAT_WS('', A, ' ', B) as C .....
That looks like some MySQL-specific voodoo. The standards-compliant way of
doing this is:
SELECT COALESCE(a,'')||' '||COALESCE(b,'') AS c
However, neither MySQL nor Microsoft SQL server support the concatenation
operator (||) correctly. Thus if you want to write code which is broadly
compatible on a variety of databases, one is forced to simply:
SELECT a, b
and then concatenate them in PHP itself:
if (strlen($row['a']) * strlen($row['b']))
$row['c'] = "{$row['a']} {$row['b']}";
else
$row['c'] = $row['a'].$row['b'];
--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
Navigation:
[Reply to this message]
|