pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Aaron Bono <postgresql@aranya.com>
To: Phillip Smith <phillips@weatherbeeta.com.au>
Cc: pgsql-sql@postgresql.org
Subject: Re: Select CASE Concatenation
Date: Fri, 7 Jul 2006 03:44:05 -0500
Message-ID: <bf05e51c0607070144p71ae45cy69ebc5c71cb39cdf@mail.gmail.com> (raw)
In-Reply-To: <011f01c6a191$34ab76e0$9b0014ac@ITPhil>
References: <011f01c6a191$34ab76e0$9b0014ac@ITPhil>

On 7/7/06, Phillip Smith <phillips@weatherbeeta.com.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

view thread (2+ messages)

Message-ID: <bf05e51c0607070144p71ae45cy69ebc5c71cb39cdf@mail.gmail.com>
Permalink:  ../bf05e51c0607070144p71ae45cy69ebc5c71cb39cdf@mail.gmail.com/
Also on:    postgresql.org/message-id/bf05e51c0607070144p71ae45cy69ebc5c71cb39cdf@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: postgresql@aranya.com, phillips@weatherbeeta.com.au
  Subject: Re: Select CASE Concatenation
  In-Reply-To: <bf05e51c0607070144p71ae45cy69ebc5c71cb39cdf@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox