March 23, 2013

Common Table Expressions

A common table expression (CTE) is a temporary named result set. CTE can be used within other DML statements like SELECT, INSERT, UPDATE, and DELETE.

It is not stored as an object and its lifetime is limited to the query.

It is defined using the WITH statement as the following example shows:

WITH EmployeeName ( EmpID, FName, LName)
SELECT EmpID, FName, LName FROM table
SELECT * FROM EmployeeName

A CTE can be used in place of a view in some instances.

No comments:

Post a Comment