Transact-SQL Reference

LEFT

Returns the part of a character string starting at a specified number of characters from the left.

Syntax

LEFT ( character_expression , integer_expression )

Arguments

character_expression

Is an expression of character or binary data. character_expression can be a constant, variable, or column. character_expression must be of a data type that can be implicitly convertible to varchar. Otherwise, use the CAST function to explicitly convert character_expression.

integer_expression

Is a positive whole number. If integer_expression is negative, a null string is returned.

Return Types

varchar

Remarks

Compatibility levels can affect return values. For more information about compatibility levels, see sp_dbcmptlevel.

Examples
A. Use LEFT with a column

This example returns the five leftmost characters of each book title.

USE pubs
GO
SELECT LEFT(title, 5) 
FROM titles
ORDER BY title_id
GO

Here is the result set:

----- 
The B 
Cooki 
You C 
Strai 
Silic 
The G 
The P 
But I 
Secre 
Net E 
Compu 
Is An 
Life  
Prolo 
Emoti 
Onion 
Fifty 
Sushi 

(18 row(s) affected)
B. Use LEFT with a character string

This example uses LEFT to return the two leftmost characters of the character string abcdefg.

SELECT LEFT('abcdefg',2)
GO

Here is the result set:

-- 
ab 

(1 row(s) affected)

See Also

Data Types

String Functions