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 |
|
Exir
Posting Yak Master
151 Posts |
Posted - 2008-11-05 : 04:38:45
|
| When i set the data type of a field something like for example varchar(10), if my inserted data be less than 10, sql fill the rest by white space. for example it will save like this "valid " instead of "valid" and it makes problem for recognizing the content of that field in my program.How can i avoid saving these white spaces in the table? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-05 : 04:43:33
|
| use ltrim(rtrim(yourfield)) |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-11-05 : 06:45:46
|
See also here (SET ANSI_PADDING):http://msdn.microsoft.com/en-us/library/ms187403(SQL.90).aspxWebfred No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
brianjensen
Starting Member
22 Posts |
Posted - 2008-11-05 : 06:56:51
|
| You could also use varchar(10) instead of char(10) as the datatype.Hmm it seems I didn't read this post properly (or else it was edited), but you shouldn't have any problems with varchar(10). |
 |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2008-11-05 : 08:45:19
|
quote: for example varchar(10), if my inserted data be less than 10, sql fill the rest by white space
This is true if the data type is CHAR, for VARCHAR it will not fill the remaining blank space- Lumbago |
 |
|
|
Exir
Posting Yak Master
151 Posts |
Posted - 2008-11-08 : 02:52:35
|
| Yes, you are right. thank you so much |
 |
|
|
|
|
|