Quoted Strings in Column Headings

A column heading in a select list can contain any character, even spaces or blanks, if the column heading is enclosed in single quotation marks ('). It can have a maximum of 30 characters. A column heading not enclosed in single quotation marks must conform to the rules for identifiers.

For example:

SELECT 'Book Publisher' = pub_name
FROM publishers

The result is:

Book Publisher
---------------------
New Moon Books       
Binnet & Hardley     
Algodata Infosystems 
Five Lakes Publishing
Ramona Publishers    
GGG&G                
Scootney Books       
Lucerne Publishing   

(8 row(s) affected)

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

SELECT 'sum' = SUM(ytd_sales)
FROM titles

Note that you can use a quoted string for a column heading in a table definition (CREATE TABLE), or in SELECT INTO and CREATE VIEW statements only if the SET option QUOTED_IDENTIFIER is set to 'ON'. Otherwise, column headings in these statements must conform to the rules for identifiers.