473,388 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

viable question

Why this always returning 'AAA'

declare @ss char(20)

set @ss='AAA'

set @ss=@ss+'BBB'
print @ss

Oct 14 '06 #1
2 1208
ad*******@yahoo.com wrote:
Why this always returning 'AAA'

declare @ss char(20)

set @ss='AAA'

set @ss=@ss+'BBB'
print @ss
Try either
declare @ss varchar(20)
or
set @ss=rtrim(@ss)+'BBB'
Oct 14 '06 #2
On 13 Oct 2006 20:13:34 -0700, ad*******@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
Oct 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul Stanial | last post by:
How viable is it to use MS Access as a front end (via ODBC) to a SQL Server 2000 database? The users would access via the internet using a netgear vpn setup. Thanks, Paul S
3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
4
by: Tosch | last post by:
I have an order processing application with many features. I want to be able to put some features in external and configureable DLLs. The main application has to pass an order object (and possibly...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
4
by: ilPostino | last post by:
I'm trying to find out if its possible to call webservices from a browser using c# or maybe some other script? I know the client would have to have ..net installed which is fine but I can't find...
3
by: Nathan Carroll | last post by:
Instead of impementing icomparer for a custom calendar class to find a button with a particular date property value I have done the following: 'on a form Private Sub Button1_Click(ByVal...
1
by: paul.drummond | last post by:
Hi all, I am new to whole idea of "web services" and architectures such as .NET and J2EE so please bare with me. I am trying to research as much as possible before asking silly questions but...
1
by: DBC User | last post by:
So far all the examples I have seen been working with simple XML files. Just curious, is Linqq a viable solution for handling a large XML file, when I say large, it means it has almost 2K+ nodes in...
6
maxx233
by: maxx233 | last post by:
I have a problem I've been butting my head up against for a while, and I really have no viable solution figured out yet :\ I would have designed the database a bit different, and certainly designed...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.