Dooes the SQL LEN()
function internally TRIM()
the data prior to calculating length of the string?
Example:
DECLARE @a VARCHAR(MAX), @b VARCHAR(MAX)
SET @a = '12345 '
SET @b = '12345 7'
SELECT @a, LEN(@a)
-- 12345 5
SELECT @b, LEN(@b)
-- 12345 7 7
Both @a
and @b
have 7 characters. @a
has 5 numeral characters and two spaces at the end.
When copying both the results from the Results window, I can see that both variables have a length of 7 chars. But when trying to find the length of the variables using LEN()
it differs. The same thing happens while storing data in a table with a varchar
column.