How to get so the rows in a table doesn't get filled with unneeded spaces to fill out everything
-
27-04-2021 - |
Question
I have a table which fills out the rows I have put in there with spaces if the thing I put in there isn't long enough.
For example:
I have a string called
'ABC'
but the column is a nchar(10)
so the value which is put in there becomes
'ABC '
Does anyone know what the problem could be?
I am working in MSSQL.
La solution
nchar
is a fixed width datatype and will always be padded out with spaces up to the defined column limit. You would need nvarchar(10)
to avoid this.
You should generally only use nchar
in preference to nvarchar
when the values in the column all have the same or very similar lengths.
Autres conseils
nchar(10)
is a fixed length string.
nvarchar(10)
is not.
You could change the column definition to nvarchar(10)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow