Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Saving query results in Excel with column names Expand / Collapse
Author
Message
Posted Thursday, March 18, 2010 1:43 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, November 17, 2014 9:24 AM
Points: 2,192, Visits: 218
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!
Post #885872
Posted Thursday, March 18, 2010 3:33 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, October 31, 2013 3:44 AM
Points: 314, Visits: 4,128
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"


Post #885953
Posted Thursday, March 18, 2010 3:39 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, November 17, 2014 9:24 AM
Points: 2,192, Visits: 218
AH...I figured it had to be something simple like that. That did it! Thank you so much!
Post #885955
Posted Thursday, March 18, 2010 3:47 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, October 31, 2013 3:44 AM
Points: 314, Visits: 4,128
You are welcome.
Post #885958
Posted Friday, March 19, 2010 3:19 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, November 5, 2014 11:16 AM
Points: 75, Visits: 622
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.
Post #886166
Posted Friday, March 19, 2010 3:51 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: 2 days ago @ 7:53 PM
Points: 9,928, Visits: 11,194
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
Post #886187
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse