Subject Re: [firebird-support] Re: String Concatenation with null field
Author Christian Danner
Hi Adam,

on Tue, 10 Jan 2006 00:46:34 -0000, you wrote:

>Let me guess, someone doesn't have a middle name
>
>select Coalesce(FirstName || ' ', '') || Coalesce(MiddleName
>|| ' ', '') || Coalesce(LastName, '') as FullName
>from employee

But if LastName isn't set...

Over-subtle solution for a mostly invisible and thus irrelevant
problem (only for hair splitters):

nullif( substring( coalesce( ' ' || name_t, '') -- Duke
|| coalesce( ' ' || name_f, '') -- Harald
|| coalesce( ' ' || name_p, '') -- van den
|| coalesce( ' ' || name_l, '') -- Leyden
|| coalesce( ' ' || name_s, '') -- II.
from 2), '')

-> 'Duke Harald van den Leyden II.'

- Prevents leading/trailing spaces under all circumstances
- Easy to extend with all fields equally processed

Ciao

Christian