Returns a substring of a string from the beginning.
The LEFT
function extracts a specified number of characters from the beginning of a string.
It is a string function and returns a string value.
LEFT ( string, number )
string
: The input string. This can be a literal string, an expression that evaluates to a string, or a column name that contains a string value.
number
: The number of characters to extract from the beginning of the string. This must be a non-negative integer.
A string containing the specified number of characters from the beginning of the input string. If the input string is shorter than the specified number of characters, the function returns the entire input string.
SELECT LEFT ('Hello World', 5); -- Returns 'Hello'
SELECT LEFT ( 'SQL Server', 6 ); -- Returns 'SQL Ser'
SELECT LEFT ( 'Short', 10); -- Returns 'Short'