Personal Notes of Edwin Eu

SQL Server – Common Table Expression (CTE)

In Microsoft SQL Server on 06/12/2012 at 8:42 AM

SQL Server  – Common Table Expression (CTE)

  • Common Table Expression (CTE) was implemented in SQL Server 2005
  • CTE are not design to be a replacement of the Temp Table
  • CTE declare the name at the beginning of code  with keyword “WITH EmpSort_CTE AS
  • CTE exampleWITH EmpSort AS

 (SELECT FirstName, LastName, EmpID, LocationID,
 ROW_NUMBER() OVER (ORDER BY LastName, FirstName) AS Position
 FROM Employee)
SELECT * FROM EmpSort
GO

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: