Blog Post

How to Copy Query Results From SQL Server 2005/2008 into Excel

,

I often work with DBAs who need to copy the results of a T-SQL query from SQL Server Management Studio (SSMS) into some portable format that is easy to save and comprehend. The easiest way that I have found is to right-click on the top left grid cell and choose either “Copy” or “Copy with Headers” (depending on whether you are running the 2005 or 2008 version of SSMS).  Only SQL Server 2008 SSMS has the “Copy with Headers” choice.

Once you make your choice, all of the cells in the result grid will be copied to the Windows Clipboard. Then, you can paste (Cntrl-V) the results into a tab of an Excel spreadsheet.

image

If you are using SQL Server 2005 SSMS, you need to enable one option to get the column headers to be copied with the other results. Just go to Tools, Options, then open Query Results, SQL Server, Results to Grid in the left tree-view control (see below). Then check the “Include column headers when copying or saving the results” option and click OK.

image

This is a far better solution than saving your results to a .rpt or .csv file, especially for the person who needs to read it later!

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating