Copy column headers and query results in SQL Server Management Studio
By: Greg Robidoux | Updated: 2006-11-07 | Comments (15) | Related: More > SQL Server Management Studio
One of the nice features with SQL Server is the ability to create result sets from queries into a grid result set. This data can then be copied and pasted in other application such as Excel. The downside to saving the results in a grid is that the column headers don't get copied along with the data. To get around this you could query the data in the text format, so you could copy the results along with the column headers, but then you are faced with formatting issues.
You have the ability to copy the column headers along with the data results. This option gets set using the query options setting. To access this setting from SQL Server Management Studio, select Query > Query Options from the menus and you will see the following screen:.
Select the Results / Grid setting and check "Include column headers when copying or saving the results". Once this is set whatever query you run and then if you select the results and copy and paste into another application the column headers are also copied along with the data.
Here is a sample query:
Results copied with column headers off:
Results copied with the column headers on:
Another way to do this is to right click on the grid result set and select Copy with Headers or use Ctrl+Shift+C as shown below.
- This is a simple little tip, but could save you time and headaches trying to get the column headers copied.
Last Updated: 2006-11-07
About the author
View all my tips