Table of Contents

Search

  1. Preface
  2. The Transformation Language
  3. Constants
  4. Operators
  5. Variables
  6. Dates
  7. Functions

Transformation Language Reference

Transformation Language Reference

LTRIM

LTRIM

Removes blanks or characters from the beginning of a string. You can use LTRIM with IIF or DECODE in an Expression or Update Strategy transformation to avoid spaces in a target table.
If you do not specify a
trim_set
parameter in the expression:
  • In UNICODE mode, LTRIM removes both single- and double-byte spaces from the beginning of a string.
  • In ASCII mode, LTRIM removes only single-byte spaces.
If you use LTRIM to remove characters from a string, LTRIM compares the
trim_set
to each character in the
string
argument, character-by-character, starting with the left side of the string. If the character in the string matches any character in the
trim_set
, LTRIM removes it. LTRIM continues comparing and removing characters until it fails to find a matching character in the
trim_set
. Then it returns the string, which does not include matching characters.

Syntax

LTRIM(
string
[,
trim_set
] )
The following table describes the arguments for this command:
Arguments
Required/
Optional
Description
string
Required
Any string value. Passes the strings you want to modify. You can enter any valid transformation expression. Use operators to perform comparisons or concatenate strings before removing characters from the beginning of a string.
trim_set
Optional
Any string value. Passes the characters you want to remove from the beginning of the first string. You can enter any valid transformation expression. You can also enter a character string. However, you must enclose the characters you want to remove from the beginning of the string within single quotation marks, for example, 'abc'. If you omit the second string, the function removes any blanks from the beginning of the string.
LTRIM is case sensitive. For example, if you want to remove the 'A' character from the string 'Alfredo', you would enter 'A', not 'a'.

Return Value

String. The string values with the specified characters in the
trim_set
argument removed.
NULL if a value passed to the function is NULL. If the
trim_set
is NULL, the function returns NULL.

Example

The following expression removes the characters ‘S’ and ‘.’ from the strings in the LAST_NAME port:
LTRIM( LAST_NAME, 'S.')
LAST_NAME
RETURN VALUE
Nelson
Nelson
Osborne
Osborne
NULL
NULL
S. MacDonald
MacDonald
Sawyer
awyer
H. Bender
H. Bender
Steadman
teadman
LTRIM removes ‘S.’ from S. MacDonald and the ‘S’ from both Sawyer and Steadman, but not the period from H. Bender. This is because LTRIM searches, character-by-character, for the set of characters you specify in the
trim_set
argument. If the first character in the string matches the first character in the
trim_set
, LTRIM removes it. Then LTRIM looks at the second character in the string. If it matches the second character in the
trim_set
, LTRIM removes it, and so on. When the first character in the string does not match the corresponding character in the
trim_set
, LTRIM returns the string and evaluates the next row.
In the example of H. Bender, H does not match either character in the
trim_set
argument, so LTRIM returns the string in the LAST_NAME port and moves to the next row.

Tips for LTRIM

Use RTRIM and LTRIM with || or CONCAT to remove leading and trailing blanks after you concatenate two strings.
You can also remove multiple sets of characters by nesting LTRIM. For example, if you want to remove leading blanks and the character 'T' from a column of names, you might create an expression similar to the following:
LTRIM( LTRIM( NAMES ), 'T' )

0 COMMENTS

We’d like to hear from you!