Re: Select statement with a NULL
- From: Toby A Inkster <usenet200703@xxxxxxxxxxxxxxxxx>
- Date: Mon, 30 Apr 2007 11:24:01 +0100
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!
.
- References:
- Select statement with a NULL
- From: Bruce A. Julseth
- Re: Select statement with a NULL
- From: Bruce A. Julseth
- Select statement with a NULL
- Prev by Date: Re: help on integrating RSS in site done in php
- Next by Date: Re: Manipulating binary data
- Previous by thread: Re: Select statement with a NULL
- Next by thread: Problem When Serializing Array With Multiline Text
- Index(es):