We’ve all got SQL that needs tidying up.

https://poorsql.com/ or https://sqlformat.org/ or http://sqlformat.darold.net/

It wont fix your syntax but it will make it look nice.