public inbox for [email protected]  
help / color / mirror / Atom feed
From: JORGE MALDONADO <[email protected]>
To: [email protected]
Subject: Query with conditional statement
Date: Wed, 13 Sep 2023 12:52:18 -0500
Message-ID: <CAAY=A78qufOUD+GLZVjNwLgBer2DxtJsHrc3h7H8r33_yuhrTw@mail.gmail.com> (raw)

Hi,

Can a conditional CASE statement be part of the SELECT 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, fldy2 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 in the example
* The AS for the alias is not supported

I need to return more than 1 field on each WHEN and also assign an ALIAS.
I very much appreciate your feedback.

Regards,
Jorge Maldonado


view thread (5+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: Query with conditional statement
  In-Reply-To: <CAAY=A78qufOUD+GLZVjNwLgBer2DxtJsHrc3h7H8r33_yuhrTw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox