Posts Tagged Common Table Expressions

Recursive Queries Using CTEs

I previously explained the basics of common table expressions (CTEs) as well as how to chain them in sequence when you need multiple temporary result sets to get the results you desire.  One of the topics I have not covered yet is using CTEs to write recursive queries. The classic example of using a recursive [...]

,

No Comments

Multiple CTEs in Sequence

In a previous post, I discussed how to use common table expressions to generate temporary result sets that can read from and written to.  In this post, I’ll show how to use two CTEs together for more complex scenarios. To illustrate how to use CTEs this way, we’ll code up a simple example using the [...]

,

1 Comment

Intro to Common Table Expressions

Common table expressions (CTEs) are a powerful feature that was added to Microsoft SQL Server 2005.  Common table expressions can be thought of as a temporary result set that can be used with one single SELECT, INSERT, UPDATE, or DELETE statement. The basic syntax for a CTE is the following: WITH <cte_name> (column1, column2, column3, [...]

,

2 Comments