Switchcase

logical-functions switchcase

syntax

  • switch(case1(condition, value),..,casen(condition, value), othervalue)

definition

Switch case results in different values depending on conditions, specified as different cases. Each case is specified with the syntax: case(condition, value). Cases are separated by commas.

The last specified value (without condition) must be configured for the values that do not meet any condition (case other).

description

The switch case function is comparable to the select case function in Visual Basic.

Use the iif function if only one case (and the case other) is needed.

applies to

conditions

  1. The domain-unit of the conditions, values and the resulting data item must match or be void (literals or parameters can be combined with data items of any domain).
  2. The values-unit of the values and the resulting data item must match.

example

attribute<string> switchA (ADomain) :=
   switch(
        case(Source/floatA <  Source/floatB, 'A < B')
      , case(Source/floatA >  Source/floatB, 'A > B')
      , case(Source/floatA == Source/floatB, 'A = B')
      , 'Missing'
   );
A(float32) B(float32) switchA
0 2 ‘A < B
1 2 ‘A < B
2 2 ‘A = B
3 2 ‘A > B
null 2 ‘Missing

ADomain, nr of rows = 5

see also