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


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, April 11, 2014 1:06 PM
Points: 1,980, Visits: 180
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


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, April 11, 2014 1:06 PM
Points: 1,980, Visits: 180
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
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, April 01, 2014 12:51 PM
Points: 74, Visits: 619
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


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 5:59 AM
Points: 11,168, Visits: 10,931
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