left

Description

Returns a specified number of characters on the left end of a character string.

Syntax

left(character_expression, integer_expression)

Parameters

character_expression

is the character string from which the characters on the left are selected.

integer_expression

is the positive integer that specifies the number of characters returned. An error is returned if integer_expression is negative.

Examples

Example 1

Returns the five leftmost characters of each book title.

use pubs
select left(title, 5) from titles
order by title_id

----- 
The B 
Cooki 
You C 
..... 
Sushi 

(18 row(s) affected)

Example 2

Returns the two leftmost characters of the character string “abcdef”:

select left("abcdef", 2)
---------
ab
(1 row(s) affected)

Usage

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

Any user can execute left.

See also

Datatypes varchar, nvarchar

Functions len, str_replace, substring