pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Select CASE Concatenation
2+ messages / 2 participants
[nested] [flat]

* Select CASE Concatenation
@ 2006-07-07 06:47 Phillip Smith <phillips@weatherbeeta.com.au>
  2006-07-07 08:44 ` Re: Select CASE Concatenation Aaron Bono <postgresql@aranya.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Phillip Smith @ 2006-07-07 06:47 UTC (permalink / raw)
  To: pgsql-sql

Hi All - Smee again!

 

Two questions but they're unrelated so I'll make 2 posts to keep it clean!

 

Number one (and I think is the easier one).

 

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.

 

Thanks,

-p



*******************Confidentiality and Privilege Notice*******************

The material contained in this message is privileged and confidential to
the addressee.  If you are not the addressee indicated in this message or
responsible for delivery of the message to such person, you may not copy
or deliver this message to anyone, and you should destroy it and kindly
notify the sender by reply email.

Information in this message that does not relate to the official business
of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta.
Weatherbeeta, its employees, contractors or associates shall not be liable
for direct, indirect or consequential loss arising from transmission of this
message or any attachments

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Select CASE Concatenation
  2006-07-07 06:47 Select CASE Concatenation Phillip Smith <phillips@weatherbeeta.com.au>
@ 2006-07-07 08:44 ` Aaron Bono <postgresql@aranya.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Aaron Bono @ 2006-07-07 08:44 UTC (permalink / raw)
  To: Phillip Smith <phillips@weatherbeeta.com.au>; +Cc: pgsql-sql

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

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2006-07-07 08:44 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-07-07 06:47 Select CASE Concatenation Phillip Smith <phillips@weatherbeeta.com.au>
2006-07-07 08:44 ` Aaron Bono <postgresql@aranya.com>

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