From phillips@weatherbeeta.com.au Fri Jul 7 06:47:56 2006 X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id BBB6A9FA6BB for ; Fri, 7 Jul 2006 03:47:56 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 94498-03 for ; Fri, 7 Jul 2006 03:47:51 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from weatherbeeta.com.au (mail.weatherbeeta.com.au [202.154.127.242]) by postgresql.org (Postfix) with SMTP id 79DAF9FA6B2 for ; Fri, 7 Jul 2006 03:47:49 -0300 (ADT) Received: (qmail 23245 invoked from network); 7 Jul 2006 06:47:47 -0000 X-NetworkBox-HamSign: 0101;OUT;wbeetaau1;c016d7dcdc9a129c9025064200c1052f; Received: from mail.weatherbeeta.com.au (HELO wb-email) (172.20.0.2)by network-box.weatherbeeta.com.au with SMTP; 7 Jul 2006 06:47:47 -0000 Received: from it-phil.weatherbeeta.com.au ([172.20.0.155]) by wb-email (602Pro LAN SUITE 2003) id 2d55aab8 for pgsql-sql@postgresql.org; Fri, 7 Jul 2006 16:46:01 +1000 From: "Phillip Smith" To: Subject: Select CASE Concatenation Date: Fri, 7 Jul 2006 16:47:24 +1000 Message-ID: <011f01c6a191$34ab76e0$9b0014ac@ITPhil> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0120_01C6A1E5.065786E0" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.6626 Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 X-Scanned-By-wbeetaau1: Virus scan performed by network-box X-Scanned-By-wbeetaau1: Scanner file id is wbeetaau1-1152254867.498-23234-000 X-Scanned-By-wbeetaau1: No known viruses found in message (received+scanned in 0.03/0.20 secs) X-Scanned-By-wbeetaau1: Spam-Check-Result: No, hits=0 required=7 tests= autolearn=no version=2.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/78 X-Sequence-Number: 25652 This is a multi-part message in MIME format. ------=_NextPart_000_0120_01C6A1E5.065786E0 Content-Type: text/plain;charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi All - Smee again! =20 Two questions but they're unrelated so I'll make 2 posts to keep it = clean! =20 Number one (and I think is the easier one). =20 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? CASE WHEN stkeoq(stock.code) =3D -1 THEN '@' WHEN stock.kit_pack =3D 'Y' THEN 'K' END AS "flags", Note: "stkeoq" is a function =20 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. =20 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 ------=_NextPart_000_0120_01C6A1E5.065786E0 Content-Type: text/html;charset="us-ascii" Content-Transfer-Encoding: quoted-printable

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) =3D -1 THEN '@'

           WHEN stock.kit_pack =3D '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
------=_NextPart_000_0120_01C6A1E5.065786E0-- From postgresql@aranya.com Fri Jul 7 08:44:15 2006 X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id EC4BA9FA68D for ; Fri, 7 Jul 2006 05:44:15 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 80062-05 for ; Fri, 7 Jul 2006 05:44:07 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.190]) by postgresql.org (Postfix) with ESMTP id B628C9FA65C for ; Fri, 7 Jul 2006 05:44:07 -0300 (ADT) Received: by nf-out-0910.google.com with SMTP id n15so126309nfc for ; Fri, 07 Jul 2006 01:44:06 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=uILn92qVxleSdbfQZdR/fjwTY9JtGyZnqSONHAghY7IlPznmD5sEwL2VR9GpDCue5SvK8fx9GH25Wi7FuF0qSssalbzplbluh0oYb9JQuEnTICv8K0CF7h42cMlrK05pQP1Xw+PckofgF2sHzReFauox7ihIJbPrjAy75b/fU50= Received: by 10.78.140.17 with SMTP id n17mr570204hud; Fri, 07 Jul 2006 01:44:06 -0700 (PDT) Received: by 10.78.29.2 with HTTP; Fri, 7 Jul 2006 01:44:05 -0700 (PDT) Message-ID: Date: Fri, 7 Jul 2006 03:44:05 -0500 From: "Aaron Bono" To: "Phillip Smith" Subject: Re: Select CASE Concatenation Cc: pgsql-sql@postgresql.org In-Reply-To: <011f01c6a191$34ab76e0$9b0014ac@ITPhil> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_106971_13711775.1152261845998" References: <011f01c6a191$34ab76e0$9b0014ac@ITPhil> X-Google-Sender-Auth: b7ce910794eabec9 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/85 X-Sequence-Number: 25659 ------=_Part_106971_13711775.1152261845998 Content-Type: text/plain; charset=WINDOWS-1252; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 7/7/06, Phillip Smith 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=85 Possible? > > > > CASE WHEN stkeoq(stock.code) =3D -1 THEN '@' > > WHEN stock.kit_pack =3D 'Y' THEN 'K' > > END AS "flags", > > > > 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= =85 > With a CASE you will need to provide all possible combinations. But perhap= s there is a way to put the two separate CASE statements together with a || concatenation: CASE WHEN stkeoq(stock.code) =3D -1 THEN '@' ELSE '' END || CASE WHEN stock.kit_pack =3D 'Y' THEN 'K' ELSE '' END AS "flags" Is this what you are looking for? -Aaron Bono ------=_Part_106971_13711775.1152261845998 Content-Type: text/html; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 7/7/06, Phillip Smith <phillips@weatherbeeta.com.au> wr= ote:

= 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=85 Possible?

&= nbsp;    <snip>

&= nbsp;    CASE WHEN stkeoq(stock.code) =3D -1 THEN '@'

&= nbsp;          WHEN stock.kit_pack =3D 'Y' THEN 'K'

&= nbsp;    END AS "flags",

&= nbsp;    <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=85

<= br>With a CASE you will need to provide all possible combinations.  Bu= t perhaps there is a way to put the two separate CASE statements together w= ith a || concatenation:

CASE WHEN stkeoq(stock.co= de) =3D -1 THEN '@'
ELSE ''
END
||

CASE WHEN stock.kit_pack =3D 'Y' THEN 'K'
ELSE ''
END