• This is maybe slightly offtopic and a year late in coming, but I just fed this query in to my T-SQL formatter (I swear I didn't specifically prepare for this query - just stumbled across it again today), turns out it parses it correctly (i.e. in the same way the SQL Server engine does), and (somewhat) clarifies what's happening!

    Link to the SQL formatted on PoorSQL.com

    Sorry about the shameless self-promotion, but I was so chuffed (pleased) when I saw the output just now, I couldn't keep it to myself 🙂

    Now I'm going to go ask John Arnott whether I can add this to my list of test cases in the project...

    http://poorsql.com for T-SQL formatting: free as in speech, free as in beer, free to run in SSMS or on your version control server - free however you want it.