The most common truncation functions are left, right, and substring.
1. LEFT (character_expression, integer_expression)
Returns the specified number of characters starting from the left of the string.
Example: left ("field name", intercepting strings)
The following example uses the LEFT function to return the leftmost two characters of the abcdefg string.
Select left ('abcdefg', 2) GO
The following is the result set:
-- AB
2. RIGHT (character_expression, integer_expression)
Returns the number of integer_expression characters starting from the right.
Example: RIGHT ("field name", intercepting strings)
The following example uses the right function to return the rightmost 2 characters of the abcdefg string.
SELECT right ('abcdefg', 2) GO
The following is the result set:
-- Fg
Take 0008
SELECT left (right ('2014-001-0008-A ', 6), 4)
3. SUBSTRING (expression, start, length)
Returns part of a character, binary, text, or image expression.
Example: SUBSTRING ("field name", starting from the nth digit, intercepting several strings)
Displays the second, third, and fourth characters in the string constant abcdef.
SELECT x = SUBSTRING ('abcdef', 2, 3)
The following is the result set:
X ---------- bcd
The most common truncation functions are left, right, and substring.