While I was writing a stored procedure that did some string manipulation and was debugging some unexpected behavior, I came across a fascinating, infurating, hidden-in-plain-sight "feature" of the LEN function: it returns the length of a string expression excluding trailing blanks. So, for example:
declare @string varchar(10)
set @string = '123456789 '
declare @len int
set @len = len( @string )
print @len
print right( @string, @len - 5 )
returns 9 and '789 ', not the expected 10 and '6789 '. Also, with this code:
declare @string varchar(10)
set @string = '123456789 ...