Re: Select CASE Concatenation - Mailing list pgsql-sql

From Aaron Bono
Subject Re: Select CASE Concatenation
Date
Msg-id bf05e51c0607070144p71ae45cy69ebc5c71cb39cdf@mail.gmail.com
Whole thread Raw
In response to Select CASE Concatenation  ("Phillip Smith" <phillips@weatherbeeta.com.au>)
List 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

pgsql-sql by date:

Previous
From: "Aaron Bono"
Date:
Subject: Re: Select Maths
Next
From: Andreas Joseph Krogh
Date:
Subject: Re: Alternative to Select in table check constraint