Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Naming of Column using CASE in SELECT statement
Wed, Aug 19 2015 6:03 AMPermanent Link

James Dooley

Avatar

Hello,

I've got the following select statement in which the name of the column using the CASE statement appears as 'CASE':

SELECT
  record_id AS Id,
  CASE action
     WHEN 'I' THEN 'Inserted'
     WHEN 'U' THEN 'Updated'
     ELSE 'Deleted'
  END CASE,
  key AS Parameter,
  value AS Value,
  actioned_by AS User
FROM parameter_xxx

And I would like to the column named 'ActionType', but if I and an AS ActionType after the CASE statement I get an error message complaining about the AS... So what is the secret to doing this???

Thanks.
Wed, Aug 19 2015 7:24 AMPermanent Link

Adam Brett

Orixa Systems

Hi James,

Here is an example:

SELECT
 ID,
 CASE
    WHEN Action = 'I' THEN 'Inserted'
    WHEN Action = 'U' THEN 'Updated'
    ELSE 'Deleted'
 END as ActionType

...

Note that the Boolean expression (Action = xxxx in this example) after WHEN must evaluate to true for the THEN to be triggered.

After the "END" you can name the column
Wed, Aug 19 2015 1:38 PMPermanent Link

James Dooley

Avatar

Thanks!
Image