Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

LEFT

Example

Retrieve three characters from the left side of a string.

SELECT LEFT(‘SQL Tutorial’3AS ExtractString;

Definition and Usage

The LEFT() function retrieves a specified number of characters from the beginning (left side) of a string.

Syntax

LEFT(stringnumber_of_chars)

Parameter Values

Parameter

Description

value

Mandatory. Specifies the string from which characters will be extracted.

format

Mandatory. Specifies the number of characters to extract from the beginning of the string. If this number exceeds the total number of characters in the string, the entire string is returned.

Technical Details

Works in:

SQL Server (from 2008 onward), Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse

More Examples

Example

Retrieve five characters from the beginning (left side) of the text stored in the “CustomerName” column.

SELECT LEFT(CustomerName, 5AS ExtractString
FROM Customers;

Example

Retrieve up to 100 characters from the beginning (left side) of a string.

SELECT LEFT(‘SQL Tutorial’100AS ExtractString;