Expressions
Table of Contents
Expressions can be used in the field list of a Select, in Insert values, in Update assignments and in Where clauses.
- Numbers: 10, -6, 3.14159
- Strings: 'single quoted' or "double quoted". A doubled quote ('It''s') is not supported. A quote that follows a backslash does not end the string, but the backslash is kept: 'It's' returns It's.
- Null: null
| Operator | Meaning |
| + | Adds numbers. When either side is a string, the values are concatenated: 'Id: ' + 5 returns 'Id: 5'. |
| - * / | Subtraction, multiplication and division. |
| % | Remainder (modulo). |
| Bitwise exclusive-or. Use Pow for exponentiation. | |
| ( ) | Grouping, with standard order of operations. |
A null on either side of + makes the result null (null propagation). Concat skips nulls instead.
These are used in Where clauses and join ON conditions:
| Operator | Meaning |
| = | Equal (strings are compared without regard to case). |
| != | Not equal. The <> form is not supported. |
| > >= < <= | Numeric comparisons. |
| LIKE, NOT LIKE | Pattern matching, see Like. |
| BETWEEN, NOT BETWEEN | Range matching, see Between. |
Comparison operators can only be used in WHERE and ON clauses. Elsewhere, use the boolean functions such as IsEqual, IsGreater and IsLike, which return 1 or 0.
-- A line comment.
SELECT Id, Name FROM WordList:Language -- A trailing comment.
/* A block
comment. */Use Declare to define a variable for the rest of the script. Variables are referenced with an @ prefix. Applications using the client API pass parameters the same way, see Client.
DECLARE @Language = 2
SELECT Text FROM WordList:Word WHERE LanguageId = @LanguageEvery SELECT needs a FROM clause. To evaluate expressions that don't read any documents, select from the built-in Single schema, which contains exactly one document.
SELECT 10 + 10 as Twenty, 'Hello' + ' ' + 'World' as Greeting, Guid() as Id FROM SingleSQL :: Concat
Concatenates all of the given values that are not null. Accepts any number of values. The + operator can also be used to concatenate, but a null on either side of + makes the whole result null.
SQL :: Count
Returns the number of values in each group. Count(0) and Count(*) count the documents in each group.
SQL :: CountDistinct
Returns the number of distinct values in each group. Values are compared without regard to case unless caseSensitive is true.
SQL :: DateAdd
Adds offset intervals to a date/time value and returns the new date/time. Use a negative offset to subtract. Interval names are not case-sensitive.
SQL :: DateDiff
Returns the number of intervals between two date/time values (date2 minus date1). See DateAdd for the interval names.
SQL :: DateTime
Returns the server's current local date and time, formatted with the optional .NET date/time format string.
SQL :: DateTimeUTC
Returns the current UTC date and time, formatted with the optional .NET date/time format string. See DateTime for the format specifiers.
SQL :: Declare
Declares a variable for the rest of a script.
SQL :: Delete
Delete removes the documents that match the given criteria.
SQL :: Detach Schema
Removes a schema (namespace) from the database and moves its files to a folder.