You are here: Re: viable question « MsSQL Server « IT news, forums, messages
Re: viable question

Posted by Hugo Kornelis on 10/14/06 21:05

On 13 Oct 2006 20:13:34 -0700, adamwalan@yahoo.com wrote:

>Why this always returning 'AAA'
>
>declare @ss char(20)
>
>set @ss='AAA'
>
>set @ss=@ss+'BBB'
>print @ss

Hi adamwalan,

Ed Murphy already supplied two fixes. The answer to the question "why"
is that char(20) is fixed-length - it's always 20 position. So if you
assign 'AAA', SQL Server pads it with 17 spaces. Then you concatenate
'BBB' to it, to get a 23-character string 'AAA (etc) BBB' - and when
you assign that back to @ss, the rightmost three bytes (the 'BBB' part)
is trimmed off.

So technically, SQL Server isn'r returning 'AAA', but 'AAA (etc) '.

And here's a short repro that clearly shows the intermediate result
before @ss+'BBB' gets trimmed for assigning it to the char(20) column.

declare @ss char(20)
set @ss='AAA'
print @ss+'BBB'


--
Hugo Kornelis, SQL Server MVP

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация