Question
· Sep 30, 2017

$CASE or $SELECT Analog in Cache´SQL

Hi, folks!

Is there any way to use $CASE or $SELECT functionality in SQL SELECT query?

E.g. something like this:

SELECT product, $CASE(status,"New":field1,"Payed":field2) as data from sales

To see either in data column either field1 or field2 values in regard of status value.

Discussion (3)1
Log in or sign up to continue

Evgeny,

in SQL you have a CASE ... END block for selection

http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=...

CASE 
  WHEN search_condition THEN value_expression
  [ WHEN search_condition THEN value_expression ... ]
  [ ELSE value_expression ]
END

CASE value_expression
  WHEN value_expression THEN value_expression
  [ WHEN value_expression THEN value_expression ... ]
  [ ELSE value_expression ]
END