Expressions

Used with variables, constants, and column names in many SQL statements, functions, and expressions. An expression returns values and can be nested.

Syntax

{constant | column_name | function | (subquery)}
[{operator | AND | OR | NOT}
{constant | column_name | function | (subquery)}...]

where

constant
Is a literal value, such as numeric or character data, or a variable identifier (in the form @variable_name). Character data must be enclosed with single quotation marks (').
column_name
Specifies a column.
function
Is a built-in function. For details, see the Functions topic.
subquery
Is a nested SELECT statement with some restrictions. A subquery can be used in an expression if the subquery returns a single value. For details, see the Subqueries topic.
operator
Is an arithmetic, bitwise, comparison, or string operator. For details, see the Operators topic.
AND
Used in Boolean expressions to connect two expressions. Returns results when both expressions are true.

When more than one logical operator is used in a statement, AND is processed first. You can change the order of execution by using parentheses.

OR
Use in Boolean expressions to connect two or more conditions. Returns results when either condition is true.

When more than one logical operator is used in a statement, OR is evaluated after AND. You can change the order of execution by using parentheses.

NOT
Negates any Boolean expression (which can include keywords, such as LIKE, NULL, BETWEEN, IN, and EXISTS).

Remarks

Character-constant expressions are treated as varchar. If they are compared with non-varchar variables or column data, the datatype precedence rules are used in the comparison (that is, the lower datatype is converted to the higher). If implicit conversion of the lower to the higher is not allowed, use CONVERT. For details, see the Functions topic.

Comparing a char expression to a varchar expression follows the datatype precedence rule (the lower datatype is converted to the higher). All varchar expressions are converted to char (that is, trailing blanks are added) for the comparison.

See Also

Functions SELECT
Operators Subqueries
Search Conditions Wildcard Characters