The following question came up when working on my CTE presentation for SQL Saturday. Does a query that JOINs a CTE to itself execute the CTE query once or twice? For instance:  ;WITH deptCTE(id, department, parent)    AS (SELECT id,department,parent FROM   Departments)SELECT q1.department,q2.department  FROM deptCTE q1 INNER JOIN deptCTE q2 ON q1.id = q2.parent WHERE q1.parent IS NULL;  The following execution plan …

CTE Query Performance 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 …

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

Last week I had the great opportunity to speak at PASS Summit 2015. My presentation was on Common Table Expressions.   Here is the sample code from the presentation. AdvancedCTEs.zip   Related Links: Common Table Expression (CTE) Month at SteveStedman.com (introduction) …

Epic Life Goal Completed: Speaking at PASS Summit – Advanced CTEs Read more »

Today I am presenting on Advanced Common Table Expressions as part of the 24 Hours of PASS conference. It is being webcast so check it out if you can. The outline for the presentation will be the following: Recursive Queries …

24 Hours of PASS – Advanced CTE Presenation Read more »