SUBSTR: Extracting a Substring

How to:

The SUBSTR function extracts a substring based on where it begins and its length in the source string.


Top of page

x
Syntax: How to Extract a Substring
SUBSTR(length, source_string, start, end, sublength, output)

where:

length

Integer

Is the the number of characters in source_string.

source_string

Alphanumeric

Is the string from which to extract a substring .

start

Integer

Is the starting position of the substring in the source string. If start is less than one or greater than length, the function returns spaces.

end

Integer

Is the ending position of the substring. If this argument is less than start or greater than length, the function returns spaces.

sublength

Integer

Is the number of characters in the substring (normally end - start + 1). If sublength is longer than end - start +1, the substring is padded with trailing spaces. If it is shorter, the substring is truncated. This value should be the declared length of output. Only sublength characters will be processed.

output

Alphanumeric



Example: Extracting a String

SUBSTR extracts the first three characters from LAST_NAME, and stores the results in a column with the format A3:

SUBSTR(15, LAST_NAME, 1, 3, 3, 'A3')

For BANNING, the result is BAN.

For MCKNIGHT, the result is MCK.


iWay Software