**Source URL:** https://general.veevavault.dev/vql/clauses/as.md

# AS



By default, VQL queries return fields in key-value pairs where the key is the field name. You can use the `AS` clause with the `SELECT` clause to define an optional alias:

* In v20.3+ (documents) and v21.1+ (objects), use the `AS` clause to define an alias for a function on a field.

* In v24.2+, use the `AS` clause to define an alias on any document or object field.

The alias name:

* Can be any string as long as it is not identical to a field name in the query target.

* Must not exceed 40 characters.

* Can only contain letters, numbers, and underscores (`_`) and cannot contain more than one consecutive underscore. Whitespaces are not supported.

* Must not be one of the reserved keywords, including VQL grammar constructs such as `SELECT`. Click below for a complete list of reserved keywords.

<DownloadButton href="sample-files/vql-restricted-keywords.csv"></DownloadButton>

Aliases are scoped to the query target. Therefore, you can use the same alias name in the main query and a subquery. If a query includes the same field both by itself and modified by a function, you must use the `AS` clause to define an alias for the function.

<Aside type="note">When a query includes the `AS` clause, the `queryDescribe` object includes `“alias”: “true”`.</Aside>

## Syntax {#Syntax}

```
SELECT {field} AS {alias}
FROM {query target}

```

## Query Examples {#Query_Examples}

The following are examples of queries using `AS`.

### Query: Aliasing Object Functions on Fields {#Query_Aliasing_Object_Functions_on_Fields}

The following query retrieves the ID and the default value of the *Packaging Text* field and uses the `LONGTEXT()` function to retrieve the full (long text) value of the *Packaging Text* field. The query uses an alias to distinguish between the default and full field values.

```
SELECT id, packaging_text__c, LONGTEXT(packaging_text__c) AS package_fulltext
FROM product__v
WHERE name__v = 'Cholecap'

```

### Response {#Response}

```
{
   "responseStatus": "SUCCESS",
   "responseDetails": {
       "pagesize": 1000,
       "pageoffset": 0,
       "size": 1,
       "total": 1
   },
   "data": [
       {
           "id": "cholecap",
           "packaging_text__c": "Your blood cholesterol level has a lot to do with\nyour chances of getting heart disease. High blood cholesterol is one of the major risk factors for heart disease. A risk factor is a condition that increases your chance of getting a disease. In fact,",
           "package_fulltext": "Your blood cholesterol level has a lot to do with\nyour chances of getting heart disease. High blood cholesterol is one of the major risk factors for heart disease. A risk factor is a condition that increases your chance of getting a disease. In fact, the higher your blood cholesterol level, the greater your risk for developing heart disease or having a heart attack. Heart disease is the number one killer of women and men in the United States. Each year, more than a million Americans have heart attacks, and about a half million people die from heart disease."
       }
   ]
}

```

### Query: Aliasing and Ordering by Object Fields {#Query_Aliasing_and_Ordering_by_Object_Fields}

The following query creates an alias for both the `name__v` field and the `country__cr.name__v` relationship and orders the results using the `name` alias:

```
SELECT name__v as name, country__cr.name__v AS country
FROM product__v
ORDER BY name

```

### Response {#Response}

```
{
   "responseStatus": "SUCCESS",
   "responseDetails": {
       "pagesize": 1000,
       "pageoffset": 0,
       "size": 4,
       "total": 4
   },
   "data": [
       {
           "name": "Adalarase",
           "country": "USA"
       },
       {
           "name": "Adalarase EX",
           "country": "USA"
       },
       {
           "name": "Amsirox",
           "country": "Canada"
       },
       {
           "name": "Cholecap",
           "country": "Canada"
       }
  ]
}

```

### Query: Using an Alias in a Function {#Query_Using_an_Alias_in_a_Function}

The following query creates an alias for the `lifecycle__v` field and then uses the alias as the argument in the `TONAME()` function:

```
SELECT id, lifecycle__v as lifecycleLabel
FROM documents
WHERE TONAME(lifecycleLabel) = 'general_lifecycle__c'

```

### Response {#Response}

```
{
    "responseStatus": "SUCCESS",
    "responseDetails": {
        "pagesize": 1000,
        "pageoffset": 0,
        "size": 3,
        "total": 3
    },
    "data": [
        {
            "id": 303,
            "lifecycleLabel": "General Lifecycle"
        },
        {
            "id": 301,
            "lifecycleLabel": "General Lifecycle"
        },
        {
            "id": 201,
            "lifecycleLabel": "General Lifecycle"
        }
    ]
}

```


---

**Previous:** [PAGEOFFSET](/vql/clauses/pageoffset)  
**Next:** [Operators](/vql/operators)