﻿ Fernhill SCADA SQL Value Expression Clauses

# Value Expression (SQL)

## Introduction

An SQL Value Expression is a sequence of Literals, Operators, and Function Calls to produce a single result.

## Syntax

value-expression ::=
value-term [ { term-operator value-term } ]

term-operator ::=
+ | -

value-term ::=
value-factor [ { factor-operator value-factor } ]

factor-operator ::=
* | / | '||'

factor ::=
[ - ] primary

primary ::=
nonparenthesized-value-primary
| ( value-expression )

nonparenthesized-value-primary ::=
literal
| primary-literal-string
| primary-literal-datetime
| primary-literal-interval
| primary-case
| primary-cast
| primary-coalesce
| primary-nullif
| primary-function-length
| primary-function-math
| primary-function-position
| primary-function-substring
| primary-function-string
| primary-function-trim
| primary-conversion-function
| primary-set-function
| primary-column-reference
| primary-dynamic-parameter
| primary-host-parameter

## Remarks

### Binary Operators

A binary operator performs an operation on two values to return a single result. These binary operators are supported:

OperatorDescriptionPrecedence
-Subtraction1
*Multiply2
/Divide2
||String concatenation2

When multiple operators are present in an expression, higher precedence operators are evaluated before lower precedence operators. When two operators have equal precedence, the left operator is evaluated before the right operator. For example:

ExpressionEvaluation Order
A + B * C B is multiplied by C, then the result is added to A
A + B + C B is added to A, then C is added to the result of A + B
A * B + C A is multiplied by B, then C is added to the result of A * B

### Parentheses

Parentheses alter the order of evaluation of operators. An expression inside parentheses is always evaluated first, regardless of operator precedence. For example:

ExpressionEvaluation Order
(A + B) * C B is added to A, then the result of A + B is multiplied by C

## Further Information

Value Expressions (SQL)