MS Access Right() Function

The Right() function in MS Access extracts a specified number of characters from the right-hand side of a string.



Right(): Definition and Usage

This function is useful for extracting portions of text from the end of a string. For example, you might use it to extract a postal code from an address or an extension from a phone number.

Syntax

Syntax

Right(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 right side of the string. If this number is larger than the length of the string, the entire string is returned. This is required.

Examples

Extracting Characters from a Literal String

This example extracts the last 4 characters from the string "SQL Tutorial is cool".

Syntax

SELECT Right("SQL Tutorial is cool", 4) AS ExtractString;
      
Output

cool
      

Extracting Characters from a Column

This example shows how to extract the last 5 characters from the 'CustomerName' column in a table called 'Customers'.

Syntax

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

A table will be returned with the 'CustomerName' column and a new column 'ExtractString', containing the last 5 characters of each customer's name.


CustomerName  | ExtractString
-----------------------------
John Doe       | n Doe
Jane Smith     | Smith