Re: Select CASE Concatenation

From: "Aaron Bono" <postgresql(at)aranya(dot)com>
To: "Phillip Smith" <phillips(at)weatherbeeta(dot)com(dot)au>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Select CASE Concatenation
Date: 2006-07-07 08:44:05
Message-ID: bf05e51c0607070144p71ae45cy69ebc5c71cb39cdf@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 7/7/06, Phillip Smith <phillips(at)weatherbeeta(dot)com(dot)au> wrote:
>
> I have a SELECT statement, part of which is a "Flags" column which is a
> CASE function, but I need to be able to concatenate the results together.
> Example: in the below, I need to be show both "@" and "K" if both of the
> CASE blocks are true… Possible?
>
> <snip>
>
> CASE WHEN stkeoq(stock.code) = -1 THEN '@'
>
> WHEN stock.kit_pack = 'Y' THEN 'K'
>
> END AS "flags",
>
> <snip>
>
> Note: "stkeoq" is a function
>
>
>
> The actual CASE is going to end up with 7 individual tests and therefore 7
> difference flags that I'll need to test and concatenate all the true ones…
>

With a CASE you will need to provide all possible combinations. But perhaps
there is a way to put the two separate CASE statements together with a ||
concatenation:

CASE WHEN stkeoq(stock.code) = -1 THEN '@'
ELSE ''
END
||
CASE WHEN stock.kit_pack = 'Y' THEN 'K'
ELSE ''
END
AS "flags"

Is this what you are looking for?

-Aaron Bono

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas Joseph Krogh 2006-07-07 09:47:13 Re: Alternative to Select in table check constraint
Previous Message Aaron Bono 2006-07-07 08:36:53 Re: Select Maths