1

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?

mpora
  • 1,411
  • 5
  • 24
  • 65
  • 3
    Similar 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 Answers1

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:

  1. Change the column in SQL Server from char to varchar (or from nchar to nvarchar).

  2. Before you use the values from the column in your code, remove the trailing spaces with Trim().

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