Export (0) Print
Expand All

Delimiting Result Set Column Names

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.

ms190195.note(en-US,SQL.90).gifNote:
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 Microsoft SQL Server ODBC drivers from SQL Server version 6.5 or earlier also truncate the result set column names to 30 characters.

The following example retrieves the product name from the Product table with a column heading of Product Name rather than the default column heading of Name:

USE AdventureWorks;
GO
SELECT Name AS "Product Name"
FROM Production.Product
ORDER BY Name ASC

In addition, Transact-SQL reserved keywords can be used in quoted column headings. For example, the following query uses the reserved word SUM as a column heading:

USE AdventureWorks;
GO
SELECT SUM(TotalDue) AS "sum"
FROM Sales.SalesOrderHeader

Transact-SQL also supports using single quotation marks ('') to delimit a result set column name. The following allows compatibility with earlier versions of SQL Server:

USE AdventureWorks;
GO
SELECT SUM(TotalDue) AS 'sum'
FROM Sales.SalesOrderHeader

Community Additions

ADD
Show:
© 2014 Microsoft