Auto-formatting of sql in Query Analyzer?

  • Hi all,

    I have a lot of lengthy queries which are autogenerated, and therefore not nicely formatted, which makes debugging a pain.

    Is there a way I can paste in an unformatted query and have Query Analyzer "pretty print" it for me?

    Is there a better tool for the job?

    Thanks for any tips!

  • Which is one of many reasons why I use AQT at http://www.querytool.com

    What i like is that you can configure exactly how you want it to re-write your queries, save it as your default configuration...

    Then everytime you build new queries they will be made in your format and style.

  • What do I lookup to figure out how to change how the formatting is done?  All I could find was the following and it wasn't very helpful...

    Format SQL

    You can format an SQL statement by clicking on Edit > Format SQL. This will reformat your SQL in a layout which is more easily read.

    • all comments will be removed from your SQL. In the future we hope to leave comments intact.
    • only select, create view and insert statements will be formatted. Other statements will not be changed (except for the removal of comments).
    • you can have up to 1000 statements in your SQL - each will be formatted in turn and delimited with a semicolon.
    • if you have selected some text, only the selected text will be formatted.

    Insert statements will be formatted in a way which makes it easy to match the insert-value with the column being inserted; if the insert statement has a column list, the column name will be given (preceded by the comment indicator --) to the right if the column value. This syntax may not be valid for many databases, for which the comment indicator can only be given at the start of a line. However such insert statements will run OK within AQT.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply