• You could also do it without cte. Why employ complex technique when you can use simple one? Cte is really great for recursion and multiple use of the same subquery, but here is not necessary. Plain-simple inline view will do.

    _____________________________________________________
    Microsoft Certified Master: SQL Server 2008
    XDetails Addin - for SQL Developers
    blog.sqlxdetails.com - Transaction log myths