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.
If you are only concerned about increasing the column width on the screen to view complete text within that column, you can do the following: -
1.) In the result set
2.) take your mouse over the column heading of the column you want to widen
3.) Using your left mouse button simply hold the line that divides two columns ( right one for the column you want to expand), and you will see your mouse cursor will change to adjustment mode (vertical black line with arrows moving out towards left and right). drag it towards the the right or left to increase or decrease the width respectively.
Just like we do it in excel, hold and drag.
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):
I reported this bug in 2008, and it was promptly closed as "Won't Fix":
Connect #356926 : SSMS : Grid alignment, column width seems arbitrary
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 be fixed in the latest builds of SQL Server 2016 (but the Connect item hasn't been updated yet).
What you can do is alias the selected field like this:
The spaces and the dot will expand the column width.
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.
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: