Format statement

  • How to format SQL for reading easier? For example, change the following code to separate lines.

    select aaa, bbb,ccc, ddd, ..., from order

    became

    select

    aaa,

    bbb,

    ccc,

    ...

    from order

  • Red Gate SQL Prompt Pro

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • indenting code is your best friend.

    while there's no hard and fast rules, i tend to do something like this:

    columns indented compared to the select

    joins are indented from the FROM statement

    this is how i, personally, without approval from anyone else, tend to format my statements for readability...your mileage may vary.

    SELECT

    aaa,

    bbb,

    ccc,

    COLUMNLIST

    FROM [order]

    INNER JOIN [OtherTables]

    ON [Order].OrderId = [OtherTables].OrderID

    WHERE Criteria = 1

    ORDER BY

    aaa,

    bbb,

    ccc,

    COLUMNLIST

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Another vote for SQL Prompt Pro[/url]. I'd hate to live without that software.

    However, you could try the Simple-Talk SQL Prettifier.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Take a look at SQL Assistant from SoftreeTech - this is another tool much like SQL Prompt. This tool works on multiple database systems (SQL Server, Oracle, mySQL, etc...) and also will work with multiple editors include notepad, notepad++, UltraEdit, etc...

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

Viewing 5 posts - 1 through 4 (of 4 total)

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