Resultset column width in Management Studio

19,236

Solution 1

No, the width of each column is determined at runtime, and there is no way to override this in any version of Management Studio I've ever used. In fact I think the algorithm got worse in SQL Server 2008, and has been essentially the same ever since - you can run the same resultset twice, and the grid is inconsistent in the same output (this is SQL Server 2014 CTP2):

enter image description here

I reported this bug in 2008, and it was promptly closed as "Won't Fix":

  • SSMS : Grid alignment, column width seems arbitrary (sorry, no link)

If you want control over this, you will either have to create an add-in for Management Studio that can manhandle the results grid, or you'll have to write your own query tool.

Update 2016-01-12: This grid misalignment issue should have been fixed in some build of Management Studio (well, the UserVoice item had been updated, but they admit it might still be imperfect, and I'm not seeing any evidence of a fix).

Update 2021-10-13: I updated this item in 2016 when Microsoft unplugged Connect and migrated some of the content to UserVoice. Now they have unplugged UserVoice as well, so I apologize the links above had to be removed, but this issue hasn't been fixed in the meantime anyway (just verified in SSMS 18.10).

Solution 2

What you can do is alias the selected field like this:

SELECT name as [name        .] FROM ...

The spaces and the dot will expand the column width.

Solution 3

How are you outputting - to text or to grid?

If to text, try this - In SSMS, go to Tools, then Options...

In Options, go to Query Results, then SQL Server. Select Results to Text and look at the Maximum Number of Characters Displayed in Each Column

See if that's set low, and if expanding it helps. You'll need to start a new query window when you make your change. Existing windows don't seem to pick up the changes.

Solution 4

I also had this issue. My solution was to change the font that was displayed in the results grid from the default sans-serif non-monospace font to one that was monospace.

One may change the font used on the results grid this way:

  1. Navigate to the Tools -> Options... menu.
  2. Within the environment cascading menu, select "Fonts and Colors". A corresponding menu is displayed to the right.
  3. In the "Show Settings For" dropdown, select "Grid Results".
  4. Select a new font and font size that is monospace. I used consolas.
  5. Save your queries and exit Microsoft SQL Management Studio.
  6. Execute a query that outputs to the grid. Monospace fonts will have column widths generated properly.

Solution 5

Resultset column width is adjusted to header text:
SELECT [FieldName] as [Header Name followed by whitespace               ]
FROM ...

Share:
19,236
Jamie Stuart Robin Parsons
Author by

Jamie Stuart Robin Parsons

3rd Year COMPSCI With High Performance Computing Student. Work at Travelers Insurance as a T-SQL admin.

Updated on June 06, 2022

Comments

  • Jamie Stuart Robin Parsons
    Jamie Stuart Robin Parsons almost 2 years

    Is there any way to alter the column width of a resultset in SQL Server 2005 Management Studio?

    I have a column which contains a sentence, which gets cut off although there is screen space.

    | foo | foo2 | description |          | foo | foo2 | description         |
    |--------------------------|    TO    |----------------------------------|
    |  x  |  yz  | An Exampl.. |          |  x  |  yz  | An Example sentence |
    

    I would like to be able to set the column size via code so this change migrates to other SSMS instances with the code.