[thelist] mysql and CONCAT...
Tris
beertastic at gmail.com
Tue Aug 21 05:39:19 CDT 2007
Perfect!
One for the code bank... um, if I had one... ;-p
Cheers!
On 21/08/07, Jason Handby <jason.handby at corestar.co.uk> wrote:
> Hi Tris,
>
>
> > I've got 2 fields.
> > Depending on the result, one might be NULL, this is intentional.
> > However, if the 2nd IS null, I want to combine it with eh first...
> > eg:
> > field1 | field2
> > sign up | NULL
> > points claimed | NULL
> > points spent | claimed prize X
> >
> > So in my output I want a new field to be created using CONCAT
> >
> > CONCAT(field1, " - ", field2) as field1
> >
> > so I WANT the output of field1 to be:
> > sign up
> > points claimed
> > points spent - claimed prize X
> >
> > but I'm getting a blank field1 if field 2 is null...
> >
> > How can I get round that?
>
> When field2 is NULL, your expression will evaluate to NULL.
>
> You probably want to use COALESCE():
>
>
> http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#functio
> n_coalesce
>
>
> Something like this:
>
> CONCAT(field1, " - ", COALESCE(field2, "")) as field1
>
>
> Jason
> --
>
> * * Please support the community that supports you. * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>
--
Give a man a fish and he'll feed himself for a day.
Give a man a religion and he'll starve to death praying for a fish.
Anon
`We are what we pretend to be, so we must be careful what we pretend to be.`
Kurt Vonnegut
`When a person can no longer laugh at himself, it is time for others
to laugh at him.`
Thomas Szasz
More information about the thelist
mailing list