Question
Evgeny Shvarov · 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.

0
0 712
Discussion (3)1
Log in or sign up to continue
SELECT
CASE
  WHEN Field1 = 1 THEN 'ONE'
  WHEN Field1 = 2 THEN 'TWO'
  ELSE NULL
END
FROM MyTable

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

Thanks Robert, Lukas, that is what I'm looking for.