Re: ADO return varchar string with space trimmed



wdwedw wrote on Fri, 29 Jul 2005 11:15:03 -0700:

> Cast to char(10) work. Can you explain why? any documentation link?

Char(10) defines the field as being a fixed character length of 10, so
whatever is written to it will be padded to it's defined length with spaces.
If you put 'A' in the field, it will be stored as 'A '

A varchar(10) field is a variable character length, up to 10 characters.
Trailing spaces are stripped, as they are the padding character. If you
write 'A ' to it, it will be stored as 'A'.

> But using varchar also working in different database. Is that a SQL server
> config problem?

No idea I'm afraid. I've only worked with SQL Server and MS Access.

Dan

> "Daniel Crichton" wrote:
>
>> wdwedw wrote on Thu, 28 Jul 2005 12:42:10 -0700:
>>
>>> I have a stored procedure like this:
>>> select CASE WHEN LEN(D1) < = 10
>>> THEN D1 + REPLICATE(' ', 10 - len(D1))
>>> ELSE LEFT(D1,10)
>>> END AS D1
>>> from table1
>>>
>>> When ADO retrieved the record in VB, the appended spaces were trimmed! I
>>> can work around with REPLICATE(N' ', 10 - len(D1)). But what's wrong?
>>
>> A varchar defined field will strip appended spaces. CAST it as a char(10)
>> and the spaces will remain.
>>
>> Dan
>>


.



Relevant Pages

  • Re: BULK COPY changes row order importing Text file
    ... Error = [ODBC SQL Server Driver]Invalid character value for cast ... BCP copy in failed ...
    (microsoft.public.sqlserver.programming)
  • Re: Development news catch-up
    ... to topline a new original movie for the cable channel, ... Does Ponce have the chops to be the lead/recurring character? ... 10-to-1 says this means a new cast. ... "Summerland") is the latest addition to the comedy pilot, ...
    (rec.arts.tv)
  • Re: The importance of Kid Vulcan as a new X-Man?
    ... successful addition to the X-Men cast, primarily as a new X-Man. ... character will be the one to break this rut. ... Will it be Kid Vulcan? ... He's set to be the driver of the first Brubaker written Uncanny X-Men ...
    (rec.arts.comics.marvel.xbooks)
  • Re: The importance of Kid Vulcan as a new X-Man?
    ... successful addition to the X-Men cast, primarily as a new X-Man. ... character will be the one to break this rut. ... Will it be Kid Vulcan? ... He's set to be the driver of the first Brubaker written Uncanny X-Men ...
    (rec.arts.comics.marvel.xbooks)
  • Re: The importance of Kid Vulcan as a new X-Man?
    ... successful addition to the X-Men cast, primarily as a new X-Man. ... character will be the one to break this rut. ... Will it be Kid Vulcan? ... he's going to be a member of the X-Men. ...
    (rec.arts.comics.marvel.xbooks)