• Then it's basically:

    WITH

    cte1

    AS

    (

    SELECT * FROM Blah1

    ),

    cte2

    AS

    (

    SELECT * FROM Blah2

    ),

    cte3

    AS

    (

    SELECT * FROM Blah3

    ),

    cte4

    AS

    (

    SELECT * FROM Fubar

    WHERE ID = cte2.ID -- notice that you can refer to earlier queries as you go down.

    )

    SELECT

    *

    FROM

    cte1

    INNER JOIN cte2

    ON cte1.ID = cte2.ID

    ETC.

    The WITH clause creates virtual tables that you can join together to your hearts content. Also, a great feature is that you can use data from one cte in another that follows it. I'm sure there's some upper limit to how many with clauses you can chain/nest together but I've never run into that barrier. If you do, let us know.