Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2007-02-28 : 08:07:29
|
| Dan writes "When executing the following statements:declare @x char(10), @y char(10)set @x = 'abc'set @y = @x + 'def'select @xselect @ythe results are:abcabcI expect @y should be equal to 'abcdef'. If I change the var types to int for example, then @y is summed correctly. Can anyone tell me why, or what I'm doing wrong? Thanks.Dan" |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-02-28 : 08:11:06
|
Either:declare @x varchar(10), @y varchar(10) orset @y = rtrim(@x) + 'def' Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
rlaubert
Yak Posting Veteran
96 Posts |
Posted - 2007-02-28 : 15:53:39
|
| The problem is you are using a fixed length variable and SQL adds spaces to the end of the value to fill out the fixed length field. As stated by snsql, using varchar will fix the problem.Raymond LaubertMCDBA, MCITP:Administration, MCT |
 |
|
|
|
|
|