Re: Select CASE Concatenation

Поиск
Список
Период
Сортировка
От Aaron Bono
Тема Re: Select CASE Concatenation
Дата
Msg-id bf05e51c0607070144p71ae45cy69ebc5c71cb39cdf@mail.gmail.com
обсуждение исходный текст
Ответ на Select CASE Concatenation  ("Phillip Smith" <phillips@weatherbeeta.com.au>)
Список 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 по дате отправления:

Предыдущее
От: "Aaron Bono"
Дата:
Сообщение: Re: Select Maths
Следующее
От: Andreas Joseph Krogh
Дата:
Сообщение: Re: Alternative to Select in table check constraint