Re: ADO return varchar string with space trimmed
- From: "Daniel Crichton" <msnews@xxxxxxxxxxxxxxxxxx>
- Date: Mon, 1 Aug 2005 11:10:30 +0100
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
>>
.
- Prev by Date: using ADO in Excel to write to Access mdb..
- Next by Date: Re: How can I create a 97 Workgroup? Engine Type=4 Jet OLEDB:Create System Database=True
- Previous by thread: using ADO in Excel to write to Access mdb..
- Next by thread: What is the SQL Text data type in ado for a Parameter?
- Index(es):
Relevant Pages
|