You are here: Functions > SUBSTRING()

SUBSTRING()

SUBSTRING() returns a substring of a character expression or field value.

Use SUBSTRING() to isolate a portion of a character expression or field value.

Function Format

SUBSTRING(C,N1,N2)

SUBSTRING() returns a sub-string of the character expression / field value C. The result is N2 characters long, starting at position N1 in the character expression/field C.

Note: When used outside of a Group command, if the string being referenced is shorter than the specified length N2, then the shorter string is returned and is not padded with blanks.

Examples

To extract "BCD" from the larger string shown below, specify:

SUBSTR("ABCDEF",2,3) = "BCD"

To extract the year out of a character field containing a date of the format “MM/DD/YYYY”, specify:

SUBSTR(CHAR_DATE,7,4)