SQL Server Management Studio returns results in Grid View, Text View and to the file. When we copy results from the Grid View to Excel there is a common complaint that the column  header displayed in resultset is not copied to the Excel. I often spend time in performance tuning databases and I run many DMV’s in SSMS to get a quick view of the server. In my case it is almost certain that I need all the time copy column headers when I copy my data to excel or any other place.
SQL Server Management Studio has two different ways to do this.
Method 1: Ad-hoc
When the result is rendered you can right click on the resultset and click on Copy Header. This will copy the headers along with the resultset. Additionally, you can use the shortcut key CTRL+SHIFT+C for coping, column headers along with the result set.
Method 2: Option Setting at SSMS level
This is SSMS level settings and I kept this option always selected as I often need the column headers when I select the resultset.
Go Tools >> Options >> Query Results >> SQL Server >> Results to Grid >> Check the Box “Include column header when copying or saving the results.”
Both of the methods are discussed in following SQL in Sixty Seconds Video.
Here is the code used in the video.
Related Tips in SQL in Sixty Seconds:
- Copy Column Headers in Query Analyzers in Result Set
- Getting Columns Headers without Result Data – SET FMTONLY ON
If we like your idea we promise to share with you educational material.
Reference:Â Pinal Dave (https://blog.sqlauthority.com)
6 Comments. Leave new
This is 2nd video numbered as #26
Thanks for note , I fixed it!
Any way to copy results where one column is character value such as 002 or 003 and paste to Excel without it dropping the lead zeroes?
Please Check – https://blog.sqlauthority.com/2012/09/24/sql-server-excel-losing-decimal-values-when-value-pasted-from-ssms-resultset/
I always get the header even when I have the setting unchecked….how do I copy without the header????
sql 2008 r2 i have changed both the options setting and tried copy with header, neither one works !!!