How to get so the rows in a table doesn't get filled with unneeded spaces to fill out everything

StackOverflow https://stackoverflow.com/questions/9211845

  •  27-04-2021
  •  | 
  •  

Вопрос

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.

Это было полезно?

Решение

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.

Другие советы

nchar(10) is a fixed length string.
nvarchar(10) is not.

You could change the column definition to nvarchar(10)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top