Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unexpected result concatenating simple strings in Sybase SQL

I'm getting unexpected results with a very simple bit of SQL, on Sybase.

declare @mystring char(30)

select @mystring = 'abc'

select 'mystring = ' + @mystring

select @mystring = @mystring + 'xyz'

select 'mystring = ' + @mystring

This returns:

mystring = abc                           
mystring = abc   

Why doesn't the last select return 'abcxyz' ?

Thanks

Bob

like image 361
user1648795 Avatar asked Jul 12 '26 06:07

user1648795


1 Answers

I suspect that this is because you have declared @mystring as char(30) and All CHAR values are blank padded up to max-length

Declaring it as varchar(30) will do the trick :

declare @mystring varchar(30)

select @mystring = 'abc' 

select 'mystring = ' + @mystring

SELECT @mystring = @mystring + 'xyz'

select 'mystring = ' + @mystring
like image 138
Vadim Tychonoff Avatar answered Jul 14 '26 23:07

Vadim Tychonoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!