Created a T-SQL formatter for mydbr

(2 posts) (1 voice)


  1. -nth-, Member

    I don't know if anyone is interested in this or not, but thought I'd share...

    For those of you (like me) who need a bit of a nudge to keep your SQL statements in top shape, I created a formatter using several open source tools. After testing it seems to be a reasonably effective solution. (Sorry, no MySQL; it's T-SQL only.)

    It runs in the background on Windows OSes and works from the client side. It uses AutoHotKey as the scripting language and Poor Man's T-SQL Formatter Command Line as the formatting engine.

    Why do this? It keeps the report code formatted to a standard pattern (proper indentation, all caps functions, etc.) which should improve readability and troubleshooting.

    Just download the following zip file which contains everything to make the solution work (source ahk code is also included): Formatter script

    Unzip the contents to "C:\apps\SQLFormatter" and run the SQLFormat_F7Hotkey executable. It will take over the F7 key so that when you're in the Report Code section of mydbr just hit F7 and it will copy the active window contents (CTRL-A,CTRL-C), format the code and replace the window contents with the new code (CTRL-V). Incidentally, the formatter should work in any SQL editor. You'll know the script is running if you see a green boxed H icon in your task tray. To exit the script, right on the icon and choose exit.

    How I use it: after creating or making changes to a report I hit F7, the code is formatted, then I hit the Execute button and I'm on my way, so it's fairly unobtrusive.

    The usual community created content warnings apply; it's provided as is, it *should* work in most Windows environments - but not guaranteed to, if something goes very wrong and blows up your SQL code I claim no responsibility. :)

    Hope this helps,

    PS - I'd love to see mydbr gain some type of SQL formatter as part of it's native tool set.


You must log in to post.