The name of a result set column is an identifier. If the name is a regular identifier that follows the rules for identifiers, it does not have to be delimited. If the name does not follow the rules for identifiers it must be delimited using either brackets () or double quotation marks (""). Double quotation marks can be used to delimit result set column names, regardless of the setting of the QUOTED_IDENTIFIER option.
Note A name of up to 128 characters can be supplied for a result set column name. However, DB-Library applications, such as the isql utility, truncate the name of any result set column to 30 characters in the query output. The SQL Server ODBC drivers from SQL Server version 6.5 or earlier also truncate the result set column names to 30 characters.
This example retrieves the publisher name from the publishers table with a column heading of Book Publisher rather than the default column heading of pub_name:
USE pubs SELECT pub_name AS "Book Publisher" FROM publishers ORDER BY pub_name ASC
In addition, Transact-SQL reserved keywords can be used in quoted column headings. For example, this query uses the reserved word SUM as a column heading:
USE pubs SELECT SUM(ytd_sales) AS "sum" FROM titles
Transact-SQL also supports using single quotation marks ('') to delimit a result set column name. This allows compatibility with earlier versions of SQL Server:
USE pubs SELECT SUM(ytd_sales) AS 'sum' FROM titles