|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 7:29 AM
Points: 1,659,
Visits: 142
|
|
I've got to be missing something pretty basic here because it doesn't seem this complicated.  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!
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Today @ 6:34 AM
Points: 254,
Visits: 3,716
|
|
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"
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 7:29 AM
Points: 1,659,
Visits: 142
|
|
| AH...I figured it had to be something simple like that. That did it! Thank you so much!
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Today @ 6:34 AM
Points: 254,
Visits: 3,716
|
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Yesterday @ 6:10 AM
Points: 74,
Visits: 599
|
|
| 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.
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 7:18 PM
Points: 10,989,
Visits: 10,532
|
|
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
Paul White SQL Server MVP SQLblog.com @SQL_Kiwi
|
|
|
|