List:General Discussion« Previous MessageNext Message »
From:RenĂ© Seindal Date:October 26 2003 8:47am
Subject:Re: How to best accomplish selecting string (unless it is null)
View as plain text  
On Sat, Oct 25, 2003 at 11:49:46PM -0500, Adam Clauss wrote:
> I have a select statement that selects two string (text) fields.  In some
> cases, the first of them may be NULL.  In this case, I would like the second
> field to be selected instead.  It is also possible that in rare cases that
> the second string may be NULL, in which case it should just return NULL.
> 
> Ex:
> I have a table similar to:
> Key   |   str1   |   str2
> 0     |  "str1"  |  "anotherstr"
> 1     |   NULL   |  "string"
> 2     |   NULL   |   NULL
> 
> 
> I would like the select statement to return:
> Key   |   Str
> 0     |   "str1"
> 1     |   "string"
> 2     |   NULL
> 
> How possible is this?

select coalesce(str1, str2);

> 
> Adam Clauss
> cabadam@stripped
> 
> 

-- 
René Seindal (rene@stripped)
Seindal Consult
Thread
How to best accomplish selecting string (unless it is null)Adam Clauss26 Oct
  • Re: How to best accomplish selecting string (unless it is null)Patrik Fimml26 Oct
  • Re: How to best accomplish selecting string (unless it is null)RenĂ© Seindal26 Oct