Column Headings from SQL Results
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.
–
Posted on April 23, 2008, in SQL Server. Bookmark the permalink. 6 Comments.







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.
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.
Pingback: Column Headings from SQL Results - Easier Way « Rhonda Tipton’s WebLog
Pingback: Dew Drop - April 24, 2008 | Alvin Ashcraft's Morning Dew
Pingback: Social Networks/Blogging and Self-Improvement « Rhonda Tipton’s WebLog
Pingback: jQuery 1.4 Reference Guide | Wow! eBook – Great ebook, great site! | AJAX WebDev Insider