last(X;Y)

Returns a string consisting of the last number of characters of a given string.

Syntax

last(X;Y)

Input

Argument Type Description
X text The string on which to apply the function

A scalar value or the name of a column

Y integer The number of characters to extract from X

Return Value

Returns a text string comprised of the last Y characters of X.

If X is N/A, the result is Y blank characters.

Sample Usage

value number last(value;number)
'banana' 3 'ana'
'banana' 4 'nana'
'banana' 2 'na'

Example

In the "Product Master" table (pub.demo.retail.prod), you can extract the substrings consisting of the last four characters of the department descriptions. To do this, create a computed column and apply the last(X;Y) function to the deptdesc column:

<base table="pub.demo.retail.prod"/>
<willbe name="example" value="last(deptdesc;4)"/>

The results are the last four characters of the values in the deptdesc column.

For example, the result for the department description named "FOOTWEAR" would be "WEAR". The result for the department description named "OFFICE SUPPLIES" would be "LIES".

Additional Information

  • This function does not work with Unicode (UTF-8) strings.
  • For a Unicode-compliant alternative, consider strextract(X;P;N).