# Calculation Operators

The equations that you build as part of a SiteSpect Calculation use the following set of mathematical and logical operators.

Operator Description
Mathematical Operators
- Subtraction
* Multiplication
/ Division
() Grouping - Follows standard mathematical order of operation rules.
= Equal to
<=> NULL-safe equal to. Performs an equality comparison like the = operator but returns 1 rather than NULL if both operands are NULL and 0 rather than NULL if one operand is NULL.
<>, != Not equal to
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
ROUND(n), ROUND(n, d) Rounds the argument n to d decimal places. d defaults to 0 if it is not specified.
Logical Operators
AND, && Logical AND. Returns 1 if all operands are nonzero and not NULL. Returns 0 if one or more operands is 0. Otherwise, it returns NULL.
OR, || Logical OR. When both operands are non-NULL, returns 1 if any operand is nonzero and 0 otherwise. If an operand is NULL, it returns 1 if the other operand is nonzero and NULL otherwise. If both operands are NULL, it returns NULL.
NOT, ! Logical NOT. Returns 1 if the operand is 0; 0 if the operand is nonzero; NULL if the operand is NULL.
Miscellaneous
NULL A NULL value represents an unknown variable in a Campaign. Any operation involving a NULL value results in NULL; a NULL value is not true in a test operation (e.g., NULL = NULL returns NULL, which evaluates to false). The Data Points for past visits to a Campaign when a Metric is added are NULL. The Value Capture Data Point for a Metric that did not match is NULL. When the location of a visit cannot be determined, the Geographic Location variables are NULL. Mobile device variables for non-mobile or unknown device users are NULL.
UNIX_TIMESTAMP(), UNIX_TIMESTAMP(date) If called with no argument, returns the current Unix timestamp (seconds since 1970-01-01 00:00:00 UTC). If called with a date argument, it returns the value of the argument as seconds since 1970-01-01 00:00:00 UTC. date is a string in the format 'YYYY-MM-DD HH:MM:SS', or a number in the format YYYYMMDDHHMMSS. The date is interpreted as a value in UTC. This function is used with the Start Time variable to perform date calculations. For example, to test if a visit started within a time frame, use an equation such as: [Start Time] BETWEEN UNIX_TIMESTAMP(20120701040000) AND UNIX_TIMESTAMP(20120705035959). Remember to convert the dates to UTC.
COUNT_STRING(match, source), Finds the number of occurrences of match in the source string.
Usage: (COUNT_STRING('"PageMatch"',[RP:1:CustomVariables])) > 5
Tests
IF(expr, then, else) If expr is nonzero and NOT NULL then this returns then, otherwise it returns else.
IFNULL(expr, else) If expr is not NULL then this returns expr, otherwise it returns else. expr LIKE pattern Performs pattern matching using SQL simple Regular Expression comparison.
% Matches any number of characters, even zero characters.
_ Matches exactly one character.
\% Matches one "%" character.
\_ Matches one "_" character.
expr REGEXP pattern Performs pattern matching using SQL Regular Expression comparison. SQL RegEx supports only a limited subset of SiteSpect's RegEx capabilities. Non-greedy quantifiers (.*?) and escape characters (\d) are not supported.
expr BETWEEN min AND max If expr is greater than or equal to min and expr is less than or equal to max, BETWEEN this returns 1, otherwise it returns 0.
expr IS NULL, expr IS NOT NULL Tests whether a value is (NOT) NULL (e.g., NULL IS NULL returns true).