Retrieve three characters from the left side of a string.
SELECT LEFT(‘SQL Tutorial’, 3) AS ExtractString; |
The LEFT() function retrieves a specified number of characters from the beginning (left side) of a string.
LEFT(string, number_of_chars) |
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. |
Works in: |
SQL Server (from 2008 onward), Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse |
Retrieve five characters from the beginning (left side) of the text stored in the “CustomerName” column.
SELECT LEFT(CustomerName, 5) AS ExtractString FROM Customers; |
Retrieve up to 100 characters from the beginning (left side) of a string.
SELECT LEFT(‘SQL Tutorial’, 100) AS ExtractString; |