Using Custum Table Expressions
i am writting a new procedure, and i wonder when is it a good idea to use custum table expressions
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Roei BarPosted Aug 8, 2009, 2:22 PM
Kirtan PatelPosted Aug 8, 2009, 2:37 PM
it is used to perform complex query like when you use count(*) and want to filter you need to write complex correlated queries to get the the result but using CTE you can get the same result by using Understandable Simple code
like consider the following query that uses count(*)
When you construct simple Query to achieve the same query gets very complex and with using CTE it make it simple one
Hope this will be Help ful to understand the usage of CTE
Dont Forget to mark "Do you like Answer" will earn me some credit :)
builckPosted Aug 8, 2009, 11:38 AM
i am talking about what microsoft calls CTE
here is a sample
;with BlaBla as
{
select * from bla
}
select * from BlaBla
when should i use this type of select
Kirtan PatelPosted Aug 8, 2009, 11:31 AM
when Using scalar subqueries (such as the
(COUNT())cannot be grouped or filtered directly in the containing query.Similarly, when using SQL Server 2005's ranking functions -
ROW_NUMBER(),RANK(),DENSE_RANK(),and so on - the containing query cannot include a filter or grouping expression to return only a subset of the ranked results.
For both of these .