Arithmetic Expressions (XQuery)

Topic Status: Some information in this topic is preview and subject to change in future releases. Preview information describes new features or changes to existing features in Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2).

All arithmetic operators are supported, except for idiv. The following examples illustrate the basic use of arithmetic operators:

The resulting type from an arithmetic operator is based on the types of the input values. If the operands are different types, either one or both when required will be cast to a common primitive base type according to the type hierarchy. For information about type hierarchy, see Type Casting Rules in XQuery.

Numeric type promotion occurs if the two operations are different numeric base types. For example, adding an xs:decimal to an xs:double would first change the decimal value to a double . Next, addition would be performed that would result in a double value.

Untyped atomic values are cast to the other operand's numeric base type, or to xs:double if the other operand is also untyped.