Selection Field Alias
You can assign an alias to any selection field. <Field alias> can later be used for more convenient referencing of this field. If you assign an alias to a selection field, you can access this field in the future using its alias in the ORDER BY and TOTALS clauses as well as when working with query results. This can be more convenient, and in some cases it is the only option.
The AS keyword can precede the field alias. You can omit this word at all, but when indicated it improves the clarity and readability of the query text.
Field aliases are defined according to the rules for assigning identifier variables. Aliases in a query cannot be the same.
Assigning aliases does not affect data selection in the query.
Example.
// You want to select
// products and groups names from the Products catalog.SELECT
Catalog.Nomenclature.Name AS Product,
Catalog.Nomenclature.Parent.Name As Group
FROM
Catalog.Nomenclature
Query result:
Product
Group
Children's pants
Clothes
"Cowboy" shirt
Clothes
Clothes
Women's jeans
Clothes
Children's sweater
Clothes Sanitaryware
Home appliances
"Lilia" sink
Sanitaryware
"Aquarium" bathroom
Sanitaryware "Ultra" mixer
Sanitaryware
Krups food processor
Kitchen accessories Braun grinder
Kitchen accessories
Krups electric knife
Kitchen accessories "Ogonek" gas stove lighter
Home appliances
Accounting calculator
Office equipment Kitchen accessories
Home appliances
Office equipment
Note that fields in the query result are named Product and Group. If you do not specify field aliases, then fields in the query result will be named Name and Name1 (field names in the query result cannot be same, therefore 1 is automatically added to the second field name) which is much less convenient
You can assign aliases to nested fields regardless of whether or not the alias of the nested table itself is provided.
Example.
// Consignment note specifications (the document, assortment and quantity)
// must be added to the report.SELECT
Document.ExpInvoice.Reference,
Dcument.ExpInvoice.Contents.(Nomenclature AS Product, Count)
Query result:
Reference
Contents
Invoice 00007 dated February 25, 2002 21:03:21
Product
Count
Women's jeans
4
Invoice 00006 dated February 25, 2002 0:00:00
Product
Count
Women's jeans
5
Invoice 00005 dated March 01, 2002 20:58:28
Product
Count
Women's jeans
1
Invoice 00004 dated March 01, 2002 20:50:40
Product
Count
Women's jeans
1
Invoice 00003 dated February 23, 2002 0:00:00
Product
Count
"Aquarium" bathroom
5
"Lilia" sink
8
"Ultra" mixer
10
Note that the field Assortment in the query result appears as a nested table, having the fields Nomenclature and Count.
Example.
// All tabular section fields of an invoice must be added to the report.
SELECT
Document.ExpInvoice.Reference,
Document.ExpInvoice.Contents.*