March 18, 2010 at 1:43 pm
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!
March 18, 2010 at 3:33 pm
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"
March 18, 2010 at 3:39 pm
AH...I figured it had to be something simple like that. That did it! Thank you so much!
March 18, 2010 at 3:47 pm
You are welcome.
March 19, 2010 at 3:19 am
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.
March 19, 2010 at 3:51 am
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