Subject | SV: [firebird-support] Best Practice re null |
---|---|
Author | Svein Erling Tysvær |
Post date | 2011-11-05T23:04:22Z |
>In certain queries I wish nulls to be treated as empty strings. For example:Sure, as long as <unknown> is the same as empty, I cannot think why not.
> Select Field1 || ' ' || Field2 AS MyOutputValue;
>
>In this example, I want the value for Field1 to be returned even if Field2 is null.
>
>My first thought is to define a default of '' for the Domains that govern all such fields. At the moment, I can't >think of a case where null values would ever be needed in those fields, but my crystal ball is not always >accurate. So:
>
>1. Is assigning a default of '' an acceptable practice?
>2. Is there a better way to handle this, perhaps within the query SQL?I won't say better, but an alternative would be something like:
Select Field1 || coalesce(' ' || Field2, '') AS MyOutputValue;
I'm assuming you don't want the space after Field1 if Field2 is NULL.
HTH,
Set