An app I’m working on is storing Unicode strings in an NVARCHAR(50) column in an SQL Server 2005 database.
Sometimes, the database returns a string padded with spaces up to the max length of the column (50). At other times the padding doesn’t happen.
I think that the type of this column was originally specified as NCHAR, but that when we realized the spaces were being added, we changed it to NVARCHAR(50). Could this have anything to do with it?
Either way, can this ‘feature’ be turned off?
Clarification
I just realized that what I wrote above doesn’t make it clear that even newly-inserted strings are getting padded with spaces.
NCHAR pads the field, NVARCHAR doesn’t. But if the data is from the old field then the spaces will remain until trimmed.