开发者

Empty space at the end of SQL Server query results

I just installed Microsoft SQL Server 2008 R2 to test with LINQ to SQL.

I have a table with one column of type nchar(20) and two rows: '123' and 'Test'.

If I query all the rows from that table and wrap each value with "'" I get the following:

'123 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ' ( _ is a space)

'Test _ _ _ _ _ _ _ _ _ _ _ _ 开发者_运维百科_ _ _ _ ' ( _ is a space)

SQL Server seems to be filling the unused space (because the column is a 20 byte nchar) with spaces.

What can I do to prevent this from happening?


Use nvarchar instead of nchar. nchar is a fixed width field that is filled with spaces, as you're seeing.


Change the column type to nvarchar.

See nchar and nvarchar.


you need nvarchar, it is flexible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜