Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to Change the Sequence of Columns in Results Pane in SSMS

Here is a really cool feature which not many of you would be aware of. All of us write simple SELECT * FROM queries in Sql Server Management Studio (SSMS). And many times, we copy the data to excel spreadsheets for additional analysis / sorting etc. Here is a simple trick to copy select columns from the results window once the results are rendered.

Go to SQL Server 2005 / 2008 Management Studio (SSMS) and open a new query window. Type a SELECT * FROM TableName query on one of the tables and run the query as shown below.


Now let us say that you want to select only the following columns in the same sequence as specified below:
  • GeographyKey
  • EnglishCountryRegionName
  • StateProvinceName
  • City
If you observe the results displayed in the previous screenshot, you can see that the columns are not in the same sequence as listed above and the query does not contain the column names, so you cant change the change the sequence of columns in the query. If you have to change the sequence of columns using the query, then you need to type in the column names. But here is a simple way to do it and no need to type the columns.

Now click on the column EnglishCountryRegionName, hold it and drag it next to GeographyKey column till you see a red color line next to the GeographyKey column header as shown below.


Now, similarly move the StateProvinceName column after EnglishCountryRegionName and before City columns as shown below.


Once all the required columns are re-arranged, you can easily copy all the required columns and copy them to excel easily as shown above.

Hope you like this trick. If there is a better and quicker way of achieving the same thing in SSMS, then let me know by leaving a comment below.

Related Articles:
  • Shortcuts for SQL Server Client Applications
  • Commonly used Keyboard Shortcuts in SQL Server Management Studio
  • Colored Connections in SQL Server 2008
  • T-SQL Coding Made Easy with Inbuilt SQL Server Templates


This post first appeared on MyTechnoBook - Datta's Technical Notes..!!, please read the originial post: here

Share the post

How to Change the Sequence of Columns in Results Pane in SSMS

×

Subscribe to Mytechnobook - Datta's Technical Notes..!!

Get updates delivered right to your inbox!

Thank you for your subscription

×