Search notes:

SQL Server function: len

Trailing spaces

len does not count trailing spaces in a string (len('bar ')) returns 3 rather than 6!). A much better way to determine the length of a string seems to be datalengh().
print(len       ('foo'   )); -- 3
print(datalength('foo'   )); -- 3
print(len       ('bar   ')); -- 3 (!)
print(datalength('bar   ')); -- 6
print(len       ('   baz')); -- 6
print(datalength('   baz')); -- 6
Github repository about-MSSQL, path: /t-sql/functions/len/trailing-spaces.sql

See also

T-SQL functions

Index