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.

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.

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!

This entry was posted in SQL Server 2008. Bookmark the permalink.

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

  1. Cindy says:

    I don’t have the copy with headers options and I have no idea why. I am using Visual Studio 2008. Any ideas?

    Thanks!
    Cindy

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s