15

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? Commented Mar 12, 2009 at 18:29
  • Are you using Enterprise Manager or Management Studio? Commented 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

Sign up to request clarification or add additional context in comments.

1 Comment

You will need to restart SQL Server Management Studio for the settings to take effect.
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.

Comments

4

This script rocks BCP to Export data to excel

Comments

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 Comment

Thanks Gregory, unfortunately I can't use the wizard since I have to automate to run every day.
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.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.