You are here: Re: Select statement with a NULL « PHP Programming Language « IT news, forums, messages
Re: Select statement with a NULL

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация