SQL Prompt - strange formatting behavior with "TOP x"

Why does SQL Prompt format SQL statements differently when using "TOP x"?

Take these two statements as an example. I would have expexted the exact formatting except for the additional two words "TOP 10" at the end of the "Select" line, but the indentation is very different:

SELECT
  [name]
 ,[object_id]
 ,[principal_id]
 ,[schema_id]
 ,[parent_object_id]
 ,[type]
 ,[type_desc]
 ,[create_date]
 ,[modify_date]
 ,[is_ms_shipped]
 ,[is_published]
 ,[is_schema_published]
FROM sys.[objects];

SELECT TOP 10
       [name]
      ,[object_id]
      ,[principal_id]
      ,[schema_id]
      ,[parent_object_id]
      ,[type]
      ,[type_desc]
      ,[create_date]
      ,[modify_date]
      ,[is_ms_shipped]
      ,[is_published]
      ,[is_schema_published]
FROM sys.[objects];
Is there a setting that makes the second statement be identically indented as the first?

Best Answer

  • Jon_KirkwoodJon_Kirkwood Posts: 418 Silver 5

    Hi @Guenter

     

    Thank you for reaching out on the Redgate forum.

     Can you try toggling Align subsequent items with first item against your Style.

     

    It can be found when editing your formatting style via Formatting Styles > Global > Lists > List items 

     Toggling that did change the behaviour of the indentation of my lists, comparing both sets of code snippets you provided.

     Hope this helps with your formatting inquiry

    Jon Kirkwood | Technical Support Engineer | Redgate Software

Answers

  • GuenterGuenter Posts: 12 Bronze 1
    Hi Jon,

    thanks for the hint. That toggle gives me the format I wanted to see!
    I do remember though, htat there was another issue that took me to set the flag otherwise, but unless I find that again, I'm happy with your solution.


Sign In or Register to comment.