Home | Submit an interview question | Filter by category | Filter by job function | Filter by company
 
Member Information
User Id
Password
 
Forgot Password
Technology Category
.NET (1202)
Languages (103)
Database (146)
Operating System (48)
Reporting (5)
Third-Party Tools (2)
Testing (91)
OOP (75)
Web Development (40)
Design Patterns (89)
General (9)
Networking (88)
Hardware (63)
Brain Exercise (2)
Others (37)
 Our Network
.NET Heaven
C# Corner
Interview Corner
Longhorn Corner
Mindcracker
VB.NET Heaven
Home » Database » Database
What do you mean by Common Table Expression?
Posted by Raghvendra Singh Jun 22, 2009
Viewed : 617 times
Major Category : Database
Minor Category : SQL Server
Total Replies : 1
Powerful ASP.NET Hosting w/ NO Setup Fees. Click Here!
Become a Sponsor
 EDITORIAL ANSWER  
No Reply Yet
 ANSWERS BY USERS  
PEEYUSH MISHRA
Jul 21, 2009

Common Table Expressions(CTE)  are a new feature  in Microsoft SQL Server 2005 that offer a more readable form of the derived table that can be declared once and referenced multiple times in a query.

WITH ProductAndCategoryNamesOverTenDollars (ProductName, CategoryName, UnitPrice)

AS

(
   SELECT    p.ProductName,
                     c.CategoryName,
                     p.UnitPrice
  FROM Products p  INNER JOIN Categories c ON c.CategoryID = p.CategoryID
  WHERE p.UnitPrice > 10.0
)

SELECT *
FROM ProductAndCategoryNamesOverTenDollars
ORDER BY CategoryName ASC, UnitPrice ASC, ProductName ASC 

This query creates a CTE named ProductAndCategoryNamesOverTenRuppes that returns the name, category name, and price of those products whose unit price exceeds 10.00.

The results of the query.

In short, a Common Table Expression allows us to define a temporary, view-like construct. We start by (optionally) specifying the columns it returns, then define the query.

  
1

 

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Advertise with us
Current Version: 2.2009.3.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved