An expression is a combination of identifiers, values, and operators that Microsoft® SQL Server™ can evaluate to get a result. The data can be used in several different places when accessing or changing data. Expressions can be used, for example, as part of the data to retrieve (in a query) or as a search condition to look for data meeting a set of criteria.
An expression can be a:
- Column name
- CASE, NULLIF or COALESCE
An expression can also be built from combinations of these entities joined by operators.
In the following SELECT statement, for each row of the result set, SQL Server can resolve LastName to a single value; therefore, it is an expression.
SELECT LastName FROM Northwind..Employees
An expression can also be a calculation, such as (price * 1.5) or (price + sales_tax).
In an expression, enclose character date values in single quotation marks. In the following SELECT the character literal B% used as the pattern for the LIKE clause must be in single quotation marks:
SELECT LastName, FirstName FROM Northwind..Employees WHERE LastName LIKE 'B%'
In the following SELECT, the date value is enclosed in quotation marks:
SELECT * FROM Northwind..Orders WHERE OrderDate = 'Sep 13 1996'
In this example, more than one expression is used in the query. For example, col1, SUBSTRING, col3, price, and 1.5 are all expressions.
SELECT col1, SUBSTRING('This is a long string', 1, 5), col3, price * 1.5 FROM mytable