CTE Query Performance

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; 

 

In the above example the query inside of the CTE gets run twice, and has no performance improvement over using the same query twice as a subquery. But it does clean up the syntax and reduce errors by only having the query in one place.

Sessions Submitted for SQL Saturday #120 Orange County CA

After being approved as a speaker at SQL Saturday 114 – Vancouver BC, and SQL Saturday 108 – Redmond WA, I have decided to give it another shot at SQL Saturday 120 in Orange County California.

I have submitted 2 abstracts for sessions:

The first one is titled Unleashing Common Table Expressions in SQL Server, and if accepted this will be the third time presenting this one on a SQL Saturday.

The next session which I will also be presenting in Vancouver BC is Using SSRS reports to analyze SQL Server health.

 

I am looking forward to travelling to sunny southern California for these presentations.  Nice to get away from the snow and rain for a while.

SQL Server Developer Edition – Under $50

Having taught several Introduction to SQL Server classes, it is always a challenge for new users to get SQL Server running on their computer for the first time. I have seen cases where people attempt to download the 90 day trial, if that even exists any more, or to download SQL Express. Here is my recommendation, for developers or anyone learning SQL Server if you need SQL Server on your laptop for a class or to just develop or try things out, then go for the SQL Server Developer Edition. SQL 2008 R2 developer edition is under $50 at Amazon.com.

My suggestion would be to go for the developer edition, it as all of the features of the full version and doesn’t expire after 90 days.

Session Accepted For SQL Saturday 108 in Redmond

I just checked the schedule and one of the sessions that I submitted for SQL Saturday 108 in Redmond WA on February 25th has been accepted.

I will be presenting Unleashing Common Table Expressions in SQL Server.

If you are going to be there, drop me an email and let me know.

This should be fun!

Snow…..

image

Snowstorm in Bellingham today.

image

More snowing coming down in Bellingham today.