14

I have a query that has approximately 20 columns and I would like to export this to an Excel file with the column headers.

I thought this would be easy to figure out but no luck! I searched the web and found one suggestion that did not end up working so I am stuck.

2
  • is this a onetime export or you trying to setup a job?
    – JoshBerke
    Mar 12, 2009 at 18:29
  • Are you using Enterprise Manager or Management Studio? Mar 12, 2009 at 18:31

5 Answers 5

30

Tools --> Options, Select "Query Results" --> "SQL Server" --> "Results to Grid" and "Results to Text" (images below):

enter image description here

enter image description here

1
  • 4
    You will need to restart SQL Server Management Studio for the settings to take effect. Mar 7, 2016 at 21:37
15

I typically do this by simply click the upper left corner in the results grid, copy, and then paste into Excel. There is one catch, you need to go into options->query results-> SQL Server->results to grid (or text if you want to save to file for import into excel) and turn on include column headers when copying or saving the results. I find this works great.

4

This script rocks BCP to Export data to excel

1

That is the default if you use the Import/Export wizard. You can also save this out to an SSIS package if you want to customize the export.

1
  • Thanks Gregory, unfortunately I can't use the wizard since I have to automate to run every day. Mar 12, 2009 at 18:37
0

I know this is an old post, but my suggestion is not obvious in MS-SSMS so I'm passing it on.

RIGHT click on the upper left corner of the results grid and select 'Save Results As' and CSV and TXT formats are the two choices in 'Save as Type'.

This works best when the query results are too big for 'cut and paste' used for smaller query results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.