Day 11 of Common Table Expression Month (June) at SteveStedman.com, today we will be taking a look at how to use multiple nested CTEs in a query. 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 set up the sample database, download it and set it up now. Russian …

Nested CTEs Read more »

Day 8 of Common Table Expression Month (June) at SteveStedman.com, today I will be building on the intro to recursive CTEs from yesterday and showing how a recursive CTE can be used to calculate information about dates of the year. This would be useful if you were trying to build a calendar. These queries will be using that database that …

Recursive CTE for Dates In A Year Read more »

Day 7 of Common Table Expression Month (June) at SteveStedman.com, today we will be taking a look at the introduction to recursive CTEs. 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 set up the sample database, download it and set it up now. The recursive feature …

Introduction to Recursive CTEs Read more »

Last year while working on my CTE presentation for a SQL Saturday I added a blog post called “Using a CTE to Split a String Into Rows“, and since that posting I have used it many times. But as things go in development, eventually there is a need to do something more. Doing some complex string building to create files …

Using a CTE to Split a String Into Rows with Line Numbers Read more »

My SQL Saturday experience originally started at a SQL Saturday in Redmond WA.  I am looking forward to the event! This year my common table expressions presentation was selected. This is going to be exciting as this CTE presentation marks the release of my CTE book which is available at Amazon.com.   Here is a zip file with the presentation …

SQL Saturday 212 in Redmond WA Read more »

One of the common questions that comes up in my CTE class/presentation asks can you use the CTE inside of a function or stored procedure. The answer is yes, but today I came across another question, how can I split a string (varchar) into rows. I did some searching but didn’t find quite what I was looking for. I did …

Using a CTE to Split a String Into Rows Read more »

Common Table Expressions are a great way to simplify complex derived table queries. If it makes sense to break out one derived table or subquery into a CTE, it can make sense to do multiple CTE’s. To use multiple CTE’s in a single query you just need to: Finish the first CTE Add a comma Declare the name and optional …

Multiple CTE’s in a single Query Read more »