Rhonda Tipton’s WebLog

Random Subject Matters

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

1

Run the query
Copy the column heading line and paste into NotePad

2

Next, put the headings on separate lines by doing CTRL-Right Arrow-Enter until you hit the end of the list

3 

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)

4

As you can see the column headings are now on Row A

5

Go back to SSMS and go to Query>Results To>Results to Grid
Run the query
6

Copy the contents and paste it in the Excel file starting in Row B

7   

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.

5 Responses to “Column Headings from SQL Results”

  1. scottstonehouse Says:

    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.

  2. Rhonda Tipton Says:

    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.

  3. Column Headings from SQL Results - Easier Way « Rhonda Tipton’s WebLog Says:

    [...] Column Headings from SQL Results [...]

  4. Dew Drop - April 24, 2008 | Alvin Ashcraft's Morning Dew Says:

    [...] Column Headings from SQL Results (Rhonda Tipton) [...]

  5. Social Networks/Blogging and Self-Improvement « Rhonda Tipton’s WebLog Says:

    [...] Column Headings from SQL Results [...]

Leave a Reply

You must be logged in to post a comment.