December 29, 2005 at 7:55 am
I have a varchar(2) column. If insert ' ' or '', I get same results.
The length of both column is zero. Please explain, why.
Thanks
December 29, 2005 at 8:15 am
Varchar() trims blanks from the right of the data. Ie. 'tom ' is stored as 'tom' but ' tom' is ' tom'.
Tom
December 29, 2005 at 8:30 am
There is actually a bit more to it depending upon the ANSI_PADDING settings...see this discussion thread:
http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=19&messageid=226423#bm226578
December 29, 2005 at 11:23 pm
A varchar will store spaces if they're part of the string that's put in the variable/field. It just won't pad with spaces to full length like char does.
Note that LEN does an RTrim before computing length.
DECLARE @str1 VARCHAR(10), @str2 VARCHAR(10)
SELECT @str1 = 'abc ', @str2 = 'abc'
SELECT LEN(@str1) as Length1, LEN(@str2) AS Length2
SELECT '[' + @str1 + ']' AS String1, '[' + @str2 + ']' AS String2
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply