Operators
HENGSHI SENSE allows the use of operators to create expressions for comparing values or performing arithmetic calculations. There are three different types of calculation operators: arithmetic, comparison, and logical.
Arithmetic Operators
Arithmetic Operator | Meaning | Example |
---|---|---|
+ (Plus) | Addition | 3 + 3 = 6 |
+? (Non-null Plus) | Treats null as 0 during addition | 3 +? null = 3 |
- (Minus) | Subtraction or Negative Sign | 3 - 1 - 1 = 1 |
-? (Non-null Minus) | Treats null as 0 during subtraction | 3 -? null -? 1 = 2 |
* (Asterisk) | Multiplication | 3 * 3 = 9 |
/ (Forward Slash) | Division | 3 / 3 = 1 |
% (Percent Sign) | Modulus (Remainder) | 16 % 5 = 1 |
^ (Caret) | Exponentiation | 16 ^ 4 = 65536 |
Comparison Operators
Comparison Operator | Meaning | Example |
---|---|---|
= | Equal to | {Region} = 'cn' |
!= | Not equal to | {Region} != 'cn' |
> | Greater than | {Sales Date} > '2009-01-01' |
< | Less than | {Sales Date} < '2009-01-01' |
>= | Greater than or equal to | {Amount} >= 20000 |
<= | Less than or equal to | {Amount} <= 100 |
<> | Not equal to | {Region} <> 'cn' |
in | In a set | {Region} in ('cn','us') |
notin | Not in a set | {Region} not in ('cn','us') |
Logical Operators
Logical Operator | Meaning | Example |
---|---|---|
and | Creates an AND condition between two expressions, where each expression has a Boolean result. If both expressions return TRUE, the combined expression also returns TRUE; otherwise, the combination returns FALSE. | ({Region} = 'cn') and ({status} = 1)) |
or | Creates an OR condition between two logical expressions. If either expression returns TRUE, the result is TRUE; the result is FALSE only when both expressions are FALSE. | (([Region] = "France") or {status} = 1 |
not | Negates the Boolean value of a logical expression. | not ({status} = 1) |
Operator Precedence
If multiple operators are combined in a single formula, they are sorted according to the table below. If the precedence values of the operators are equal, they are sorted from left to right. Parentheses can be used to adjust the calculation order, with the calculations inside parentheses having the highest precedence.
For example, if an expression contains both multiplication and division operators, they are calculated in the order they appear from left to right in the expression. The operator precedence in the table below is arranged from highest to lowest.
Operator | Description |
---|---|
^ | Exponentiation |
– | Sign (e.g., –1) |
* , /, % | Multiplication, Division, Modulus |
+, +?, –, -? | Addition, Non-null Addition, Subtraction, Non-null Subtraction |
=, !=, <, >, <=, >=, <> | Comparison |
in, notin | Membership in a set |
not | Logical NOT |
and | Logical AND |
or | Logical OR |
Example: Combination of and
and or
expressions
5 > 6 or 5 < 3 and 5 = 5
Calculation steps:
5 > 6
, returnsfalse
5 < 3
, returnsfalse
;5 = 5
, returnstrue
; Logical AND, returnsfalse
- Logical OR, returns
false