September 15, 2004

Varchar string and spaces

I expect every varchar string with no precedding spaces and suffixing
spaces but SQL Server 2000 surprised me today. For example, if we
execute below statements,

Declare @abc varchar(50)
Select @abc=' abc '
Select len(@abc)

What do you expect? I expected it to be 3 while it is actually 4, but
why? Because damn Microsoft SQL Server 2000 doesn't remove precedding
spaces even to a varchar string.

No comments: