SQL Server Common Table Expressions

added by BlackWasp
6/25/2012 8:54:11 AM

3 Kicks, 253 Views

Avoiding temporary tables and cursors for queries can lead to scripts that are easier to understand and maintain, and that provide better performance than the cursor-based alternative. One option for complex queries is the use of common table expressions.


2 comments

dpeterson
6/25/2012 8:53:42 AM
It's funny, the only time I've actually used CTE's is for operations involving the use of row_number(). Most of the time I just join to an aliased query rather than following the CTE syntax (which gives me backwards compatibility to SQL 2000).

BlackWasp
6/25/2012 4:16:48 PM
That's reasonable. I still have some source code out there somewhere using SQL2000, though I'm trying to get people to use SQL2012 now and a lot of the stuff I do requires SQL2005 as a minimum. I do like the ease of syntax for hierarchical queries in CTEs though.