Recently I faced a issue when using len()
in a query to find out the length of a query, len()
was not counting the trailing spaces in the value. Bu
len counts the number of characters used not the storage required, this will be even more evident when you use nvarchar instead of varchar
len does not count trailing spaces either
take a look at this
declare @v nchar(5)
select @v ='ABC '
select len(@v),datalength(@v)
and the output for len is 3 while the output for datalength =10