• By the way, something that helped me is starting to use Common Table Expressions (CTE). It really helps to organize heavily nested code and make it readable.

    (For those who don't know what I mean:

    WITH a AS ( complex query ),

    b AS ( complex query ),

    SELECT a.*, a2.key

    LEFT JOIN a ON criteria AS a2

    LEFT JOIN (SELECT * FROM a INNER JOIN b)

    etc...

    You can use the expressions multiple times in the query afterwards but even when you don't, it already becomes more readable.

    Has anyone got experience with the automatic query formatters? I already found out that the one by Red Gate (SQL Prompt) is working well, the cheaper one SQL Pretty Printer already caused some crashes...