Skip to main content

RIGHT

Functions › Text › Take part of a string

Returns the last characters of a string.

Syntax​

RIGHT( <string>, <n> )

Arguments​

ArgumentDescription
<string>The text to take from.
<n>How many characters to take. A negative number takes all but the first -<n> characters.

Returns​

Text. NULL when any argument is NULL. The whole string when <n> is at least its length.

Usage notes​

  • RIGHT('invoice', -2) is voice.
  • A <n> that is not an integer is an error.
  • On large tables the engine runs it in the data store when <n> is a literal of 0 or more; otherwise it runs after the rows are read.

Examples​

File extensions of four characters:

SELECT f.name, RIGHT(f.name, 4) AS ext
FROM tables.drive.file f
WHERE RIGHT(f.name, 4) = 'xlsx'
nameext
q1.xlsxxlsx
budget.xlsxxlsx

See also​

LEFT · SUBSTRING · RPAD · SPLIT_PART