Indented keywords
viacoboni
Posts: 13
I prefer this format
The main point here is 2 spaces after SELECT, two-space indent on FROM, JOIN, WHERE, GROUP BY, HAVING, and ORDER BY (main clauses), and an extra two spaces on AND and OR in WHERE and JOIN clauses. Advantage? All the typical code lines up under the column list, without a large indent that visually disconnects keyword from clause. A LEFT JOIN, GROUP BY, or ORDER BY breaks up the column aligning but thats OK.
A major difference from the shipping product is that AND and OR align indented from the keyword, not the parenthesis. If parenthesis are included, aligning from them is fine (but this is rarer than no parenthesis).
If an INSERT...SELECT, the SELECT is indented two spaces and all its subclauses get the extra 2 spaces also.
Any chance we could see this?
SELECT column1, column2 FROM T1 JOIN T2 ON T1.a = T2.a LEFT JOIN T3 ON T1.a = T3.a AND T2.b = T3.b WHERE T1.b = 'some criteria' AND T2.b = 'something else' GROUP BY column1 HAVING Count(*) > 1 ORDER BY column1
The main point here is 2 spaces after SELECT, two-space indent on FROM, JOIN, WHERE, GROUP BY, HAVING, and ORDER BY (main clauses), and an extra two spaces on AND and OR in WHERE and JOIN clauses. Advantage? All the typical code lines up under the column list, without a large indent that visually disconnects keyword from clause. A LEFT JOIN, GROUP BY, or ORDER BY breaks up the column aligning but thats OK.
A major difference from the shipping product is that AND and OR align indented from the keyword, not the parenthesis. If parenthesis are included, aligning from them is fine (but this is rarer than no parenthesis).
If an INSERT...SELECT, the SELECT is indented two spaces and all its subclauses get the extra 2 spaces also.
UPDATE Table1 SET Col1 = Col2 WHERE Col2 = 'something' DELETE Table1 FROM Table1 JOIN Table2 ON Table1.col1 = Table2.col1 WHERE Table1.Col2 = 'something'
Any chance we could see this?
Comments
Regards,
Andras
Red Gate Software Ltd.
Essentially everything aligns on the space after the select statement with enough room for the largest keyword.
http://www.solidrockstable.com/blogs/PragmaticTSQL