AS clause

The AS clause allows you to give an alias name to EQL attributes and results.

The alias name can be given to an attribute, attribute list, expression result, or query result set. The aliased name is temporary, as it does not persist across different EQL queries.

Alias names must be NCName-compliant (for example, they cannot contain spaces). The NCName format is defined in the W3C document Namespaces in XML 1.0 (Second Edition), located at this URL: http://www.w3.org/TR/REC-xml-names/.

Note:

Attribute names are not required to be aliased, as the names are already NCName-compliant. However, you can alias attribute names if you wish (for example, for better human readability of a query that uses long attribute names).
AS is used in:
  • DEFINE statements, to name a record set that will later be referenced by another statement (such as a SELECT or FROM clause).
  • RETURN statements, to name the EQL results. This name is typically shown at the presentation level.
  • SELECT statements, to name attributes, attribute lists, or expression results. This name is also typically shown at the presentation level.
Assume this DEFINE example:
DEFINE EmployeeTotals AS
SELECT
  DimEmployee_FullName AS Name,
  SUM(FactSales_SalesAmount) AS Total
FROM SaleState
GROUP BY DimEmployee_EmployeeKey, ProductSubcategoryName;

In the example, EmployeeTotals is an alias for the results produced by the SELECT and GROUP BY statements, while Name is an alias for the DimEmployee_FullName attribute, and Total is an alias for the results of the SUM expression.

Using AS expressions to calculate derived attributes

EQL statements typically use expressions to compute one or more derived attributes. Each aggregation operation can declare an arbitrary set of named expressions, sometimes referred to as derived attributes, using SELECT AS syntax. These expressions represent aggregate analytic functions that are computed for each aggregated record in the statement result.

Important

Derived attribute names must be NCName-compliant. They cannot contain spaces or special characters. For example, the following statement would not be valid:
RETURN price AS SELECT AVG(Price) AS "Average Price"
The space would have to be removed:
RETURN price AS SELECT AVG(Price) AS AveragePrice