Why does the t-sql LEN () function ignore trailing spaces?

Description of the LEN () function on MSDN : returns the number of characters of the specified string expression, excluding trailing spaces .

Why was the LEN () function designed this way? What problem does this problem solve?

Connected:

+5
source share
2 answers

It captures auto-complete rows due to the length of the data type. Consider the following:

DECLARE @Test CHAR(10), @Test2 CHAR(10)
SET @Test = 'test'
SET @Test2 = 'Test2'
SELECT  LEN(@Test), LEN(@Test + '_') - 1, LEN(@Test2), LEN(@Test2 + '_') - 1

4, 10, 5 10 . , @Test , 10. LEN , LEN(@test) LEN(@Test2) . , , LEN . /, .

+6

,

CREATE TABLE tblSomething ( variable_length varchar(20), non_var_lenght char(10) ); 
-1

All Articles