Column Headings from SQL Results
Posted by Rhonda Tipton on April 23, 2008
I have had some one-off requests to basically dump data from SQL Server to an Excel spreadsheet. I am the kind that wants to make the spreadsheet look decent, so I would like to at least have column headings. The below process provides a less painful way to get column headings from a SQL results grid into Excel.
In SSMS, go to Query>Results To>Results to Text
Run the query
Copy the column heading line and paste into NotePad
Next, put the headings on separate lines by doing CTRL-Right Arrow-Enter until you hit the end of the list
Copy the list and paste into Excel starting on line 2
Once in Excel, do a Ctrl C, select A1 and Paste/Paste Special and Check transpose (ok)
As you can see the column headings are now on Row A
Go back to SSMS and go to Query>Results To>Results to Grid
Run the query ![]()
Copy the contents and paste it in the Excel file starting in Row B
–
This process helps tremendously when the result set contains more than 20 fields; however, if you find yourself pulling the same data on a regular basis, I recommend using SQL Server Integration Services or Excel automation.
–





















April 24, 2008 at 6:49 am
Try this:
—
In SSMS, under tools–>options
In the tree on the left, go to Query Results–>SQL Server–>Results to Grid
In the list on the right, check “Include column headers when copying or saving the results”.
Click OK.
—
Now the headers should be copied automatically for you. Why this isn’t the default setting is a mystery to me.
April 24, 2008 at 7:41 am
Wow. Thanks Scott. Now this is what the Internet and Blogs are all about. To learn… I had no idea about this setting and am very anxious to pass it on.
April 24, 2008 at 8:18 am
[...] Column Headings from SQL Results [...]
April 24, 2008 at 9:22 am
[...] Column Headings from SQL Results (Rhonda Tipton) [...]
May 7, 2008 at 6:42 pm
[...] Column Headings from SQL Results [...]