---
schema_version: "1"
id: 792d457e674e5a2bee1664e23bfe05159ccb66aa3f14b0ab5e47d5238930f4e9
title: trim(LEADING | TRAILING | BOTH, {chars}, {str})
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_sql/guides/bi-sql-string-trim.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-sql/guide/bi-sql-string-trim.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 5eba0c195ab551a2725dee981fd192b3e6e9e92a1766f0cd29a488d3f0ccf80e
products:
  - SQL for Analytics Developer Guide
  - analytics
---

# trim(LEADING | TRAILING | BOTH, {chars}, {str})

Removes leading or trailing characters from a string. If no characters are specified, the function removes blank spaces.

**note:** The trim function isn’t supported in Analytics Studio. An error occurs when the function is used in the UI. The function is available using the Query API. For more information, see [Query CRM Analytics Data with the Query API](https://developer.salesforce.com/docs/atlas.en-us.bi_dev_guide_rest.meta/bi_dev_guide_rest/bi_rest_api_query_data.htm).

- `LEADING`

  - : Optional. Specify to remove characters from the beginning of the string.

- `TRAILING`

  - : Optional. Specify to remove characters from the end of the string.

- `BOTH`

  - : Optional. Specify to remove characters from both the start and end of the string.

If `LEADING`, `TRAILING`, or `BOTH` aren't specified, `trim()` defaults to `BOTH`.

## Example

This example shows all variations of the `trim()` function for removing the characters "A", "b", and "n" from the beginning, end, or both sides of the City field string.

```nolang
SELECT City, Trim('Abn' FROM City) as TrimCity, Trim(LEADING 'Abn' FROM City) as LTrimCity, Trim(TRAILING 'Abn' FROM City) as RTrimCity, Trim(BOTH 'Abn' FROM City) as BothTrimCity
FROM "Superstore"
GROUP BY City
LIMIT 5;
```

| City        | TrimCity   | LTrimCity  | RTrimCity   | BothTrimCity |
| ----------- | ---------- | ---------- | ----------- | ------------ |
| Aberdeen    | erdee      | erdeen     | Aberdee     | erdee        |
| Abilene     | ilene      | ilene      | Abilene     | ilene        |
| Akron       | kro        | kron       | Akro        | kro          |
| Albuquerque | lbuquerque | lbuquerque | Albuquerque | Ibuquerque   |
| Alexandria  | lexandria  | lexandria  | Alexandria  | lexandria    |
