My string contains leading and trailing spaces (see below).
When I applied the LRTIM function it appears to work. Next, when I nest the LTRIM function with the LEN function to the string, it appears the length is off by 1 (i.e. length of original string is 16, LTRIM removed the single (1) leading space from the string, so I expected LEN to return a length of 15, not 14). Any explanations?
SELECT
' This is a test ' AS origStr
,LEN(' This is a test ') AS origStrLen
,'[' + LTRIM(' This is a test ') + ']' AS ltrimStr
,LEN(LTRIM(' This is a test ')) AS strLtrimLen
;
Results:
This is a test | 16 | [This is a test ] | 14 |