The following is chapter 6 from my Common Table Expressions book in its entirety. READER NOTE: Please run the CTEBookSetup.sql script in order to follow along with the examples in this chapter. The script mentioned in this chapter is available at http://SteveStedman.com. Thinking of the proverb “two heads are better than one” makes me think, it really depends on the people. Two people working together are …

Multiple CTEs in a Query Read more »

The following is chapter 5 from my Common Table Expressions book in its entirety. READER NOTE: Please run the CTEBookSetup.sql script in order to follow along with the examples in this chapter. The script mentioned in this chapter is available at http://SteveStedman.com. Hierarchical CTEs When looking at the table of contents for a book it is generally represented as an outline of some kind utilizing indentation, …

Hierarchical Queries Read more »

The following is chapter 4 from my Common Table Expressions book in its entirety. READER NOTE: Please run the CTEBookSetup.sql script in order to follow along with the examples in this chapter. The script mentioned in this chapter is available at http://SteveStedman.com. Recursive CTEs Have you ever solved a maze puzzle on paper, or had the opportunity to visit a …

Recursive CTEs Read more »

Back in 2012 when I was writing my Common Table Expressions book, I came up with the following CTE in a function to split a string into rows. Original Post: http://stevestedman.com/2012/04/using-a-cte-to-split-a-string-into-rows/ At the time, I thought it was pretty handy function, I ended up including it as an example in my CTE book, and I have used it dozens of …

CTE to Split a String in a function SplitString Read more »

I will be speaking at SQL Saturday Denver, presenting on Advanced Common Table Expressions.  This presentation should be a lot of fun.  I will be covering all the advanced and fun CTE features that I haven’t had time to fit into my introduction to CTE session in the past. Here is the outline of the session: 1.Recursive CTEs. 2.Hierarchical CTEs. …

In Denver for SQL Saturday Read more »

June was an exciting month for me with Beta 6 of the Database Health Reports releasing at the beginning of the month, and this being CTE Month at SteveStedman.com to mark the release of my Common Table Expressions book. CTE Month Summary CTE Month postings started with the basics on June 1st, and grew throughout the month to include more …

End of June Summary Read more »

Day 14 of Common Table Expression Month (June) at SteveStedman.com, today we will be taking a look at data paging with CTE’s and how it compares to the offset and fetch in T-SQL 2012. Now on to CTE Data Paging. These queries will be using that database that was set up in a previous posting on the CTE_DEMO Sample Database, if you haven’t …

CTE Data Paging Read more »