Saving query results in Excel with column names

  • I've got to be missing something pretty basic here because it doesn't seem this complicated. :w00t:

    I want to save the results of a query to an Excel spreadsheet. No problem, highlight the rows and columns and paste in Excel or right-click and save as a csv. However, neither of these bring accross the column names though and I have many columns that I would need to type into Excel.

    Is there a way to also grab the column names? Thanks!

  • This are the steps in SSMS for Sql 2008 but I think it should work for 2005:

    Click on the Tools menu option in SSMS.

    Click on Options->Query Results->Sql Server->Results to Grid

    Tick "Include Column Headers when Copying or Saving the Results"

  • AH...I figured it had to be something simple like that. That did it! Thank you so much!

  • You are welcome.

  • You could also put the query in the Excel spreadsheet using the external data source tool. Once that is done you could just refresh the spreadsheet on the fly.

  • You can also write the output directly to a file from SSMS.

    Choose 'output to file' instead of 'output to grid'.

    You might also like to check the option to 'quote strings containing list separators when saving .csv results'.

    Yet another alternative is to use the SQLCMD extensions built in to SSMS, there is an example here on MSDN

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply