Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qgWed-00G7gC-OS for pgsql-sql@arkaria.postgresql.org; Wed, 13 Sep 2023 20:40:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qgWeb-0028bZ-CO for pgsql-sql@arkaria.postgresql.org; Wed, 13 Sep 2023 20:40:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qgWea-0028bN-T0 for pgsql-sql@lists.postgresql.org; Wed, 13 Sep 2023 20:40:04 +0000 Received: from mail-yw1-x112e.google.com ([2607:f8b0:4864:20::112e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qgWeX-004OYe-Jw for pgsql-sql@postgresql.org; Wed, 13 Sep 2023 20:40:03 +0000 Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-58c92a2c52dso2550807b3.2 for ; Wed, 13 Sep 2023 13:40:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694637600; x=1695242400; darn=postgresql.org; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:from:to:cc:subject:date:message-id :reply-to; bh=FGxpXsumfcR3xDpYw4paTb5sUJOTIjxBxKAhNbmncvo=; b=Xh5arDUDlnyLpwxdwIgo3RcMtUqZmohge2J26mR7dMpbAIJJly5U4OjM7+x/VF/E+0 fKzr5ilbz6DJJ8i5AX719lyLX0Fbb0XB+vUe3FqtGTSh93AayfzPlRrF3yVqkE0pn74Q ehnZ8oJT0qciqUNqTfDybEGthQJIh5htEmv3ydYH/+ik8VHrAg0JlX7xmM+S2Kc8KtO9 5JtWENwYBV7YZuf2OtannJYlOK1O3OH/P4IsrrDvTNbvVZ780GFZo/lVKGBji81d5KC1 E/P9KjFcw6HlookKXHcjcQD9XBv/Np/uz5JhqJ+l6DgEXsumBwihwBEQc4a9SWzZ9ZPR qMzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694637600; x=1695242400; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FGxpXsumfcR3xDpYw4paTb5sUJOTIjxBxKAhNbmncvo=; b=ifhPWALuUdtaouIWmtrs14lfvJSEyfgyYWBP2fvz6mAG62cf70vC5gub04tq1LqqZ4 bx9mbfOobDaaPDjQb+I3025qzsBkKVzafnOnMf2P1LHvOV2BV7vnFBNvUsD5XNVNCWkR 5FAnvVARKvqeUyMrCFleWSqF1VOLJs2GL+R0JW4lwYr90j8faKKFgCjqeKc6ApGNfNnu c2ml9QGJOG4S9vznmStwrj6Mqs1DuhcMdelYRhsP9KLgwOYOiv2vj6kqRpJ9pxmbgNHq x+MUwkbhUcet2tj7qJ4A17+KyrcV/idITU7wNXd51KRop45igXY3MwYhxXmAcn2itMZE rcHA== X-Gm-Message-State: AOJu0YyClqX49hMcNg75sGKzzmXmUb3E2xqNc8zgv51zO6dKL82x9f5I qsxzDk9oMfmW95Hg/1fN6MA= X-Google-Smtp-Source: AGHT+IH7y5srrHobiFKi3ycZ8nkfdEYG7MCkUFceaPDFoxVUDFlht0tXyiMgZIPzXjkXv001AULAnQ== X-Received: by 2002:a81:840e:0:b0:59b:85c:404a with SMTP id u14-20020a81840e000000b0059b085c404amr3969110ywf.6.1694637600048; Wed, 13 Sep 2023 13:40:00 -0700 (PDT) Received: from smtpclient.apple ([2600:381:ec09:a60a:fc58:8356:1539:6479]) by smtp.gmail.com with ESMTPSA id u74-20020a81844d000000b0057087e7691bsm3321345ywf.56.2023.09.13.13.39.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Sep 2023 13:39:59 -0700 (PDT) Content-Type: multipart/alternative; boundary=Apple-Mail-8819A634-8043-40FC-82F1-B41CF20DB9B4 Content-Transfer-Encoding: 7bit From: Shane Borden Mime-Version: 1.0 (1.0) Subject: Re: Query with conditional statement Date: Wed, 13 Sep 2023 16:39:49 -0400 Message-Id: References: Cc: JORGE MALDONADO , pgsql-sql@postgresql.org In-Reply-To: To: "Tchouante, Merlin" X-Mailer: iPhone Mail (20G81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail-8819A634-8043-40FC-82F1-B41CF20DB9B4 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable You will need to do a CASE statement for ea= ch column.  I=E2=80=99m not aware of being able to return multiple colu= mns from one case. 

Shane Borden
sborden76@= gmail.com
Sent from my iPhone

=
On Sep 13, 2023, at 4:23 PM, Tchouante, Merlin <= ;mtchouan@umaryland.edu> wrote:

=EF=BB=BF =

Yes, it can.=

 

Thanks,

  -- Merlin=

 

 

Merlin D. Tchouante,&nb= sp;Sr. IT Enterprise Application Developer
Center for Info= rmation Technology Services (CITS)
601 West Lombard S= treet
Baltimore, Maryla= nd 21201-1512
mtchouan@umaryland.edu 
410-706-4489 * 410-706-1500 fax<= span style=3D"color:#242424">

 

Please send Blackboard questions to the CITS support email address:<= /span>  DL-CITSBbSupport@umaryland.edu

Please send Mediasite questions to the CITS support email address:  DL-CI= TSMediasiteSupport@umaryland.edu

 

<image001.png>

 

From: JORGE MALDONADO <jorgemal1960@gmail.c= om>
Sent: Wednesday, September 13, 2023 1:52 PM
To: pgsql-sql@postgresql.org
Subject: Query with conditional statement

 

You don't often get email from jorgemal1960@gmail.com. Learn why this is important

CAUTION: This message originated from a non-UMB em= ail system. Hover over any links before clicking and use caution opening att= achments.

Hi,

 

Can a conditional CASE statement be part of the SELEC= T portion of a query? For example:

 

SELECT

fld1, fld2, fld3,

CASE 

    WHEN condition1 THEN fldx1 AS a1, fldx2= AS a2, fldx3 AS a3

    WHEN condition2 THEN fldy1 AS b1, f= ldy2 AS b2, fldy3 AS b3

    ELSE .....

END,

fld6, fld7

FROM ......

WHERE ......

 

I ran a test and see the following:

* Each WHEN only accepts 1 result and not 3 as shown i= n the example

* The AS for the alias is not supported

 

I need to return more than 1 field on each WHEN and a= lso assign an ALIAS.

I very much appreciate your feedback.

 

Regards,

Jorge Maldonado

= --Apple-Mail-8819A634-8043-40FC-82F1-B41CF20DB9B4--