This example returns two characters, beginning with character 4, from a string literal. The return result is "ph".
SUBSTRING("elephant",4,2)
This example returns the remainder of a string literal, beginning at the fourth character. The return result is "phant". It is not an error for the length argument to exceed the length of the string.
SUBSTRING ("elephant",4,50)
This example returns the first letter from the MiddleName column.
SUBSTRING(MiddleName,1,1)
This example uses variables in the position and length arguments. If Start is 1 and Length is 5, the function returns the first five characters in the Name column.
SUBSTRING(Name,@Start,@Length)
This example returns the last four characters from the PostalCode variable beginning at the sixth character.
SUBSTRING (@PostalCode,6,4)
This example returns a zero-length string from a string literal.
SUBSTRING ("Redmond",4,0)