# LEFT

{% hint style="info" %}
**Important Notice: Migration of Documentation Website**

Please be advised that our documentation website is currently undergoing a migration to a new platform. To ensure you have access to the most up-to-date information, we kindly request that you visit our new documentation website located at:

[Official Snowflake Snowconvert Documentation](https://docs.snowflake.com/en/migrations/snowconvert-docs/translation-references/transact/README)

For any immediate assistance or if you encounter any issues, please contact our support team at [snowconvert-support@snowflake.com](mailto:snowconvert-support@snowflake.com).

Thank you for your understanding.
{% endhint %}

<details>

<summary>Applies to</summary>

* [x] SQL Server
* [x] Azure Synapse Analytics

</details>

## Description

Returns the right part of a character string with the specified number of characters. ([RIGHT in Transact-SQL](https://docs.microsoft.com/en-us/sql/t-sql/functions/right-transact-sql?view=sql-server-ver15)).

## Sample Source Pattern

### Syntax

{% tabs %}
{% tab title="SQL Server" %}
```
LEFT ( character_expression , integer_expression )  
```
{% endtab %}

{% tab title="Snowflake SQL" %}
[Snowflake SQL complete documentation](https://docs.snowflake.com/en/sql-reference/functions/left.html)

```
LEFT ( <expr> , <length_expr> )
```
{% endtab %}

{% tab title="JavaScript" %}
Function used to emulate the behavior

```javascript
function LEFT(string, index){
      if(index < 0){
          throw new RangeError('Invalid INDEX on LEFT function');
      }
      return string.slice( 0, index);
    }
  return LEFT(STR, INDEX);

```
{% endtab %}
{% endtabs %}

## Examples

{% tabs %}
{% tab title="SQL Server" %}
**Code:**

{% code title="IN -> SQLServer_01.sql" %}
```sql
SELECT LEFT('John Smith', 5) AS FIRST_NAME;
```
{% endcode %}

**Output:**

```
FIRST_NAME|
----------+
John      |
```
{% endtab %}

{% tab title="Snowflake SQL" %}
**Code:**

{% code title="OUT -> SQLServer_01.sql" %}
```sql
SELECT LEFT('John Smith', 5) AS FIRST_NAME;
```
{% endcode %}

**Output:**

```
FIRST_NAME|
----------+
John      |
```
{% endtab %}

{% tab title="JavaScript" %}
**Code:**

```sql
CREATE OR REPLACE FUNCTION left_str(str varchar, index float)
RETURNS string
LANGUAGE JAVASCRIPT
AS
$$
    function LEFT(string, index){
      if(index < 0){
          throw new RangeError('Invalid INDEX on LEFT function');
      }
      return string.slice( 0, index);
    }
  return LEFT(STR, INDEX);
$$;
SELECT LEFT_STR('John Smith', 5) AS FIRST_NAME;
```

\
**Output:**

```
FIRST_NAME|
----------+
John      |
```
{% endtab %}
{% endtabs %}

## Known Issues <a href="#known-issues" id="known-issues"></a>

No issues were found.

## Related EWIs <a href="#related-ewis" id="related-ewis"></a>

No related EWIs.
