Difference between SELECT Alias = ColumnName and SELECT ColumnName AS
I have noticed two different approaches to specifying the name of a column in a resultset differently from the table column name. The one I am most familiar with is of the form SELECT ColumName as AliasName FROM TheTable But I am now quite frequently seeing SELECT AliasName = ColumnName FROM TheTable From what I can tell, these behave in exactly the same way, but I am curious if there are, in fact, any subtle differences, or an advantage with one approach over the other?
Overall, there's no real difference, but since the equals sign is for assignment or comparison, I leave it at that.You can't alias a table with an equals sign, so using it for column aliases just feels weird. I alias using AS.
I am one of the early promoters of Alias = column name OR Alias = formula (circa 1999-2000). For me, it is about legibility (which increases understanding and speed). The SQL code that you write is read far more frequently than it is written/rewritten. And even before it can be rewritten it must be read. Usually, when we as developers are reading something it is to reverse engineer it and/or to problem solve starting with an issue that occurred downstream such as the report / UI layer. If your code is as simple as Alias/column name then the difference is "six and half a dozen of the other". But often when aliasing something it is because their is a transformation/calculation. Case statements and calculations can get UGLY! So to the point made above rationalizing his preference for using ColumnName as Alias. **If you are doing string manipulation or some sort of formula or calculation than isn't that the same as assignment?** **Usually** when I look at a stored procedure or other SQL code, **I do not need or want to read every single case statement and formula for my assigned task**. If my alias come first and the ugly formulas and calculations are indented properly, I only need to read what I need. Again personal preference. If your code is ugly I WILL REFORMAT. if it poorly performs, I will rewrite it. If not I may leave everything the same except what I need to change.