I have linked a table from an SQL Server to Access database but the contents of text-based columns have right trailing spaces. Does anyone know what causes this?
Asked
Active
Viewed 774 times
1
-
3Similar to: http://stackoverflow.com/questions/4166159/sql-where-clause-matching-values-with-trailing-spaces/4166186#4166186 Also http://technet.microsoft.com/en-us/library/ms187403.aspx relevance – xQbert Aug 16 '13 at 19:58
1 Answers
2
The columns in the SQL Server table are probably char
or nchar
columns.
In contrast to varchar
and nvarchar
, their length is fixed.
This means that when you save a five-character string in a char(50)
column, SQL Server fills the remaining 45 characters with spaces. That's where your trailing spaces come from.
There are two things you can do:
Change the column in SQL Server from
char
tovarchar
(or fromnchar
tonvarchar
).Before you use the values from the column in your code, remove the trailing spaces with
Trim()
.

Christian Specht
- 35,843
- 15
- 128
- 182