FSQLF is open source SQL code formatter (just like the title says). Try it out, I hope it will be usefull for you.

Please, let me know any comments that you might have (in the forum). Advises how to improve something would be very welcome ;)