MS Access Left() Function

The Left() function in MS Access extracts a specified number of characters from the beginning (left-hand side) of a string. It's a very useful function for extracting specific parts of text data.



LEFT(): Definition and Usage

Left() is particularly helpful for extracting prefixes or initial portions of strings. You specify the string and the number of characters to retrieve from the left side. If you ask for more characters than the string contains, it simply returns the entire string.

Syntax

Syntax

Left(string, number_of_chars)
      

Parameter Values

Parameter Description
string The string from which you want to extract characters. This is required.
number_of_chars The number of characters to extract from the left. If this number exceeds the length of the string, the entire string is returned. This is required.

Examples

Extracting Characters from a Literal String

This extracts the first three characters ('SQL') from the string 'SQL Tutorial'.

Syntax

SELECT Left("SQL Tutorial", 3) AS ExtractString;
      
Output

SQL
      

Extracting Characters from a Column

This example extracts the first five characters from the 'CustomerName' column in the 'Customers' table (assuming a table named 'Customers' exists with a 'CustomerName' column).

Syntax

SELECT Left(CustomerName, 5) AS ExtractString
FROM Customers;
      
Output

ExtractString
-------------
(The first five characters of each CustomerName will be displayed here.)
      

**Note:** The second example's output will depend on the data in your `Customers` table. Each row in the output will contain the first five characters of the `CustomerName` for that row. If a `CustomerName` is shorter than five characters, the entire name will be returned. For extracting characters from the right-hand side of a string, see the `Right()` function.