C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






CTE in SQL 2005


Posted Date: 13 May 2008    Resource Type: Articles    Category: Databases
Author: NagarajanMember Level: Gold    
Rating: Points: 10



Common Table Expressions ( CTE in short) is one of the new and cool feature that comes with SQL 2005. A CTE is an expression that outputs a result set, which is temporary hybrid derived table, like a temporary table. CTEs can be used for all DML statements and specially select statements.

It also provide a powerful way of doing recursive and nested queries in a syntax that is usually easier to code and review than other methods.
Though new to SQL Server, Common Table Expressions are part of ANSI SQL 99, or SQL3.

Clause like Compute, Order By (without a TOP), INTO, Option, FOR XML, and FOR BROWSE are all not allowed.

Syntax

[ WITH [ ,...n ] ]

::=
expression_name [ ( column_name [ ,...n ] ) ]
AS
( CTE_query_definition )

WITH OrderProducts(ProductName, OrderQuantity) AS
(
SELECT ProductName, Quantity as OrderQuantity From Orders O, Product P Where O.ProductId = P.ProductID
)
Select * From OrderProducts;

CTEs should be used in the very next statement of the declaration, they can't be used in other statements.





Responses

Author: Mahesh Raj    07 Jun 2008Member Level: Gold   Points : 1
This is very good information,Continue posting such useful articles.


Author: sivakumar    08 Jun 2008Member Level: Silver   Points : 1
Hi

Thanks.I expect this answer.


Regards
siva



Author: John Fernandez    08 Jun 2008Member Level: Gold   Points : 1
Very well written Article.Thanks for sharing this information.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: MS SQL Server Reporting Services and you
Previous Resource: Group By Functions in SQL Server Part 1
Return to Discussion Resource Index
Post New Resource
Category: Databases


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use