Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

Expressions (Database Engine)

An expression is a combination of identifiers, values, and operators that SQL Server can evaluate to obtain a result. The data can be used in several different places when you are 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 when looking for data that meets a set of criteria.

An expression can be any of the following:

  • Constant

  • Function

  • Column name

  • Variable

  • Subquery


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.

USE AdventureWorks2008R2;
SELECT LastName 
FROM Person.Person;

An expression can also be a calculation such as (price * 1.5) or (price + sales_tax).

In an expression, enclose character and datetime values in single quotation marks. In the following SELECT statement, the character literal B% that is used as the pattern for the LIKE clause must be in single quotation marks:

USE AdventureWorks2008R2;
SELECT LastName, FirstName 
FROM Person.Person 
WHERE LastName LIKE 'Bai%';

In the following SELECT statement, the date value is enclosed in quotation marks.

USE AdventureWorks2008R2;
SELECT c.FirstName, c.LastName, e.HireDate 
FROM Person.Person c JOIN HumanResources.Employee e 
ON c.BusinessEntityID = e.BusinessEntityID
WHERE e.HireDate = 'July 1, 2007';

In the following example, more than one expression is used in the query. For example, Name, SUBSTRING, ProductNumber, ListPrice, and 1.5 are all expressions.

USE AdventureWorks2008R2;
   SUBSTRING('This is a long string', 1, 5) AS SampleText, 
   ListPrice * 1.5 AS NewPrice
FROM Production.Product;
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.