op:when

op:when(
   $condition as item(),
   $value as item()*
) as map:map

Summary

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
$condition A boolean expression.
$value The value expression to return if the boolean expression is true.

Example


xquery version "1.0-ml";

import module namespace op="http://marklogic.com/optic"
     at "/MarkLogic/optic.xqy";

let $employees := op:from-view("main", "employees")
 
return $employees
    => op: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"
	   ))))
    => op:result()    
  
Powered by MarkLogic Server | Terms of Use | Privacy Policy