Brandon168
Brandon168

Reputation: 21

MS SQL - LTRIM(RTRIM([columnName])) won't remove blank spaces on text output

How to remove blank spaces on the righthand side when column defined nvarchar(255) and data is less than 255 characters?

I have some columns defined as nvarchar(255). The select LTRIM(RTRIM([Column])) would not remove blank spaces on the right when output to either text or file even using about trim option. However, it would remove blank spaces when output to GRID from SSMS. How can I remove spaces without reducing the column size on the table?

Thanks, Brandon.

Upvotes: 0

Views: 659

Answers (1)

Martin Smith
Martin Smith

Reputation: 453628

When choosing the option to output query results to text or file in SSMS the columns are fixed width. The width is chosen based on the column datatype.

The same width is used for the column in all rows.

The only way to reduce this is by casting the column to a smaller datatype if it is unnecessarily large and never needs the declared width.

Upvotes: 0

Related Questions