Drag and drop query result columns in SQL Server Management Studio
There are so many new little features in SQL Server Management Studio, finding all of them is a challenge and sometimes you just accidentally find things without even looking. One nice feature of the query tool is the ability to display your results in a table format. This makes it very easy to copy and paste the results for SQL Server into an Excel spreadsheet, Access table or some other application. Although this is great there are times when it would be nice to reorder the columns in the query results. For queries that you write this is pretty easy by just changing the column order, but if you have a query that took a long time to run or if you have no control over the output from a stored procedure or some other system function it is sometimes easier to just copy the results into Excel and then change the column order for the results. Luckily in SQL Server SQL Server Management Studio there is a new way to do this.
As mentioned before there are a lot of new little features in SQL Server Management Studio. Once nice little change is the ability to drag your output result columns into a different location without having to rerun the query.
Here is a screenshot of a simple query where all data is pulled from the HumanResources.Employee table. As you can see the EmployeeID is the first column and NationalIDNumber is the second column.
If you left click on a column and drag the column to some other position the data output is changed without having to rerun the query. The following screenshot shows how to select and drag the column.
This next screen shot shows the query results in a different order without having to modify and rerun the query.
The other nice thing about doing this reorganization of the output columns is that when you copy and paste the data the format stays the same, it does not revert back to the original format from the query output. Here is a sample copy of the data from SQL Server into an Excel spreadsheet.
So there you have it, another nice little feature of SQL Server Management Studio.
- Add this tip to your list of tricks
- And here are some other tips with related info to using the query tool
About the author
View all my tips
Article Last Updated: 2007-01-18