op.when( booleanExpression as xs.boolean, valueExpression as String ) as whenExpression
This function executes the specified expression if the specified condition is true
for the row. Otherwise, the expression is not executed and the next 'when' test is checked
or, if there is no next 'when' text, the otherwise expression for the
op.case
expression is executed.
Parameters | |
---|---|
booleanExpression | A boolean expression. See Boolean Expression Functions for the list of functions used to build boolean expressions. |
valueExpression |
The value expression to return if the boolean expression is
true .
|
const op = require('/MarkLogic/optic'); const employees = op.fromView('main', 'employees'); employees.select(['EmployeeID', op.as('cased', op.case([ op.when(op.eq(op.col('EmployeeID'), 2), 'second'), op.when(op.eq(op.col('EmployeeID'), 3), 'third')], 'otherwise'))]) .result();
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.