I don't like Things On The Right End Of The Line because they are often off the edge of the screen and out of sight.
Be interested to know, for folk that do that, whether it is "always done it that way" or "deliberately do it that way BECAUSE"
Here's what I do, compare to the Right-End way:
SELECT [MyAliasName1] = MyColumnName1, [MyAliasName2] = CASE ... some really long conditional code ... ,
more common Right-End way:
SELECT MyColumnName1 AS [MyAliasName1], CASE ... some really long conditional code ... AS [MyAliasName2],
to my way of thinking the Alias Name can be off the right hand edge of the screen and not spotted / taken into consideration
By the by we ALWAYS use "AS" for aliases - I'd love to have a "Fussy"/EXPLICIT flag/setting in SQL that made the parser moan about the absence of things like that. All too easy to miss a comma, for example:
SELECT MyColumn1 -- Forgot to put a comma after this one MyColumn2
such that MyColumn2 becomes the alias for MyColumn1. (I think the way to fix that is to Alias all tables and prefix ALL columns with the Alias Name. To my mind that makes the code look very busy, so we only use Table Alias names where there is ambiguity - i..e the presence of them indicates something out of the ordinary. This is helped, for us, because our Column names are unique within the database, not just the table - so basically we only need them when a table is used more than once.
We always use AS if we use an Alias Name for a Table
FROM MyTable1 AS T1 JOIN MyTable2 AS T2 ON ...
another area where I commonly see Right-End coding is the JOIN
FROM MyTable1 AS T1 JOIN MyTable2 AS T2 ON T2.SomeID = T1.SomeID AND ... length join conditions ... LEFT OUTER JOIN MyTable3 AS T3 ON
to my mind that, too, is risky. The fact that T3 is Outer Joined can be off screen and not noticed. It might be an APPLY or a JOIN ...
In fact we don't do Right-End with Parenthesis, Brackets, BEGIN/END etc.
IF @Parameter = 1 BEGIN SELECT Col1, Col2, ... FROM ( SELECT Col1, Col2, ... FROM MyTable1 WHERE ... UNION ALL SELECT Col1, Col2, ... FROM MyTable2 WHERE ... ) AS X JOIN ... ORDER BY ... END ELSE BEGIN .... END
in this example the BEGIN, END and ELSE all line up. I don't have the BEGIN at the Right End out of sight. I know that SQL does't care what spacing / alignment I use, but it is common in other languages to have a "Lint" tool which WILL moan about Logic not matching code-alignment which is helpful to find "run on" code.
(We ALWAYS use BEGIN / END, even for a single-statement. Odds are good that someone will stick a DEBUG statement in there, or more/new code, and not spot that the single-statement has now become multi-statement)
The "(" and ")" also line up, in particular I do not do:
IF @Parameter = 1 BEGIN FROM ( SELECT Col1, Col2, ... FROM ... ) AS X END
What I am after is that at-a-glance I can spot things that are wrong, before I ever try to execute the code, let along put it in production - often referred to as "defensive programming"
I'd be interested to hear from folk that Right-End code such things, and why you think that is less error-prone / more defensive