Thread: Select CASE Concatenation

Select CASE Concatenation

From
"Phillip Smith"
Date:
<div class="Section1"><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:11.0pt;
font-family:Arial">Hi All – Smee again!</span></font><p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size:11.0pt;
font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:11.0pt;
font-family:Arial">Two questions but they’re unrelated so I’ll make 2 posts to keep it clean!</span></font><p
class="MsoNormal"><fontface="Arial" size="2"><span style="font-size:11.0pt; 
font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:11.0pt;
font-family:Arial">Number one (and I think is the easier one)…</span></font><p class="MsoNormal"><font face="Arial"
size="2"><spanstyle="font-size:11.0pt; 
font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:11.0pt;
font-family:Arial">I have a SELECT statement, part of which is a “Flags” column which is a CASE function, but I need to
beable to concatenate the results together. Example: in the below, I need to be show both “@” and “K” if both of the
CASEblocks are true… Possible?</span></font><p class="MsoNormal"><font face="Courier New" size="2"><span
style="font-size:11.0pt;
font-family:"Courier New"">     <snip></span></font><p class="MsoNormal"><font face="Courier New" size="2"><span
style="font-size:11.0pt;
font-family:"Courier New"">     CASE WHEN stkeoq(stock.code) = -1 THEN '@'</span></font><p class="MsoNormal"><font
face="CourierNew" size="2"><span style="font-size:11.0pt; 
font-family:"Courier New"">           WHEN stock.kit_pack = 'Y' THEN 'K'</span></font><p class="MsoNormal"><font
face="CourierNew" size="2"><span style="font-size:11.0pt; 
font-family:"Courier New"">     END AS "flags",</span></font><p class="MsoNormal"><font face="Courier New"
size="2"><spanstyle="font-size:11.0pt; 
font-family:"Courier New"">     <snip></span></font><p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size:11.0pt;
font-family:Arial">Note: “stkeoq” is a function</span></font><p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size:11.0pt;
font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:11.0pt;
font-family:Arial">The actual CASE is going to end up with 7 individual tests and therefore 7 difference flags that
I’llneed to test and concatenate all the true ones…</span></font><p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size:11.0pt;
font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:11.0pt;
font-family:Arial">Thanks,</span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:11.0pt;
font-family:Arial">-p</span></font></div><br /><p><b>*******************Confidentiality and Privilege
Notice*******************</b><p>The material contained in this message is privileged and confidential to the addressee.
Ifyou are not the addressee indicated in this message or responsible for delivery of the message to such person, you
maynot copy or deliver this message to anyone, and you should destroy it and kindly notify the sender by reply email.
<p>Information in this message that does not relate to the official business of Weatherbeeta must be treated as neither
givennor 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 <br /> 

Re: Select CASE Concatenation

From
"Aaron Bono"
Date:
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