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 |
|
olily
Starting Member
37 Posts |
Posted - 2002-05-20 : 01:37:04
|
| I have a field with varchar(50) in TrxTable. When I load the records into a datagrid, I noticed that all 50 chars are loaded into the datagrid's column even the records only accomodate less than 50 chars. This will cause problem when I try to add a few chars(without manually delete the spaces) into the column through the datagrid. At first I used char(50) but this definitely won't work. So I changed the datatype to varchar(50). I'm using VB6 and Sql Server 7.0. Any advice to solve this? |
|
|
rihardh
Constraint Violating Yak Guru
307 Posts |
Posted - 2002-05-20 : 04:00:38
|
| Because CHAR is a fixed lenght column all data that has been inserted using this type has a fixed lenght. After you changed to VARCHAR the blank spaces stayed. There are different approaches how to handle this; you could create another column with varchar datatype and copy the data to that column truncating the values of blank spaces using LEFT in combination with CHARINDEX (if the column holds only one word),when there are multiple words it gets a little more tricky...For future projects lookup bol for ANSI_PADDING. |
 |
|
|
olily
Starting Member
37 Posts |
Posted - 2002-05-20 : 04:21:13
|
| I redownloaded my data after changed the datatype to varchar.Thanks! |
 |
|
|
|
|
|