Style Question - How to indent JOINS after primary table?

This is my preferred personal SQL style. I can ALMOST, but not quite get it defined using the style editor in SQLPrompt.

SELECT
    TOP 100
    inventory_user_id
    , email_addr
    , person
    , inventory_user.user_id
FROM
    dbo.inventory_user
        INNER JOIN dbo.default_app_settings
            ON default_app_settings.settings_id = inventory_user.settings_id
        LEFT JOIN prod_api.dbo.cms_user AS cms_user
            ON cms_user.user_id = inventory_user.user_id
WHERE
    cms_user.user_id > 0

The remaining things I can't seem to figure out.

1. How to get TOP 100 on its own line so I can -- comment it out quickly as needed
2. How to indent the INNER JOIN / LEFT JOIN so they are 1 indent further over then the primary table name.

I have been going through a lot of settings but can't seem to figure this out. I know it's minor, but I've been doing SQL like this for 20 years and it's just enough of an annoyance that every time I reformat things I have to go fix these two items.

Please help

Tagged:

Answers

  • Dan_JDan_J Posts: 465 Silver 2
    Hi @ApiDbGuy

    Thanks for reaching out to us regarding this.

    1. It is possible to get TOP 100 on it's own line. If you open Formatting styles settings, select Data (DML) under STATEMENTS and check 'Place DISTICT/TOP clauses on new line', this should allow the formatting you are after.

    2. Unfortunately it isn't currently possible to align JOIN as far over as you are looking to. I will escalate this to our development team to see if they are able/willing to add additional formatting options for this. I will come back to you on this as soon as I have an update for you.
    Kind regards

    Dan Jary | Redgate Software
    Have you visited our Help Center?
Sign In or Register to comment.