-1

When is the name of the flavor of sql that supports "=" for alias instead of using "as"?

SELECT 
 A = Col1
,B = Col2
FROM Table

as opposed to SQL-86

SELECT
  Col1 AS A
, Col2 AS B
FROM Table
e-Fungus
  • 321
  • 3
  • 17
  • 1
    Certainly both were supported in SQL Server 2000, trying to find anything older than that needs one to find/install older versions of BOL or look through dead trees. But even if an answer was available, what *problem* would it help you solve, beyond getting an answer right in a trivia quiz? – Damien_The_Unbeliever Mar 05 '21 at 15:08
  • 1
    (ANSI/ISO SQL) The boolean expression `A = Col1` returns TRUE, FALSE or null/unknown. I.e. has nothing to do with "aliasing". – jarlh Mar 05 '21 at 15:20
  • Trying to add a correct reference so reviewer can lookup if needed and acknowledge that it will work for a given environment before deploying. This is true for some older reviewers. i.e. see jarlh comment. obviously he never seen this syntax, if he was a reviewer, I would have to rewrite the code in the old syntax. – e-Fungus Mar 05 '21 at 15:30
  • 1
    I think this goes back to Sybase days (in the Sql Server world anyway.) – shawnt00 Mar 05 '21 at 15:38
  • 2
    `A = Col1` never introduced a column alias in standard SQL. That's a boolean expression that compares the column `A` with the Column `Col1` –  Mar 05 '21 at 15:39
  • 1
    The flavor of SQL supported by SQL Server is called T-SQL, incidentally, and like almost all flavors of SQL it does not fully conform to standard SQL. If you're concerned about compatibility or being understood by as many reviewers as possible, use `AS` only, as the "expression form" is nonstandard -- T-SQL gets away with it because it *also* lacks a boolean type. – Jeroen Mostert Mar 05 '21 at 15:56
  • Let's just say that any DB of some complexity is going to have to use features which are not available in other systems. If that is what the reviewer is obsessing about (rather than e.g. the lack of schema reference on the table, and no table reference on the columns, and many other things besides) then I don't think they're doing their job properly. – Charlieface Mar 05 '21 at 16:16
  • For those who still says that aliasing is not possible with equal in TSQL/ nothing to do with aliasing, see the current https://learn.microsoft.com/en-us/sql/t-sql/queries/select-clause-transact-sql. the last optional syntax ` | column_alias = expression. ` – e-Fungus Mar 05 '21 at 22:10

1 Answers1

1

This is of a great surprise to me. It seems that the column_alias = expression has always been part of the original syntax of T-SQL.

The AS command was added to T-SQL.80 (2000) to be SQL-92 compatible.

Excerpt of SQL2000_release.pdf page 1459

The AS clause is the syntax defined in the SQL-92 standard for assigning a name to a result set column. This is the preferred
syntax to use in Microsoft® SQL Server™.

column_name AS column_alias

Or

result_column_expression AS derived_column_name

Transact-SQL also supports the following syntax for compatibility with earlier versions of SQL Server:

column_alias = column_name
e-Fungus
  • 321
  • 3
  • 17