Calculated fields and renaming column titles

You can rename column titles using the AS keyword. For example:

SELECT Department AS Dept, FirstName, LastName FROM Employee;

This simply shortens the column header for the returned results table. More usefully, you can name computed fields. Using the Employee table as an example:

SELECT Department, FirstName + " " + LastName AS Name FROM Employee;

produces the following:

Department

Name

TECH

Phil Roach

TECH

Chris England

SALES

Andreas Smith

ADMIN

Jim Smith

SALES

Julia Allan

Note that the space in between the FirstName and LastName is required to properly format the result.

Numeric field types can also be used to create calculated columns. Here are some examples:

SELECT Age + 2 AS [Age in two years] FROM Employee;

SELECT Age * 2 AS DoubleAge FROM Employee;

See also:

Next topic - applying a sort order

Selecting records - the basics

Other types of SQL statements