How many times have you had to write a quick query for someone in SQL Management Studio and then export the data to Excel? Exporting data from SQL Server is a lengthy process and involves several steps, but if you do it multiple times, it’s not bad.
One thing I learned about saving SQL query results in Excel or CSV format is that it is better to use the SQL Import and Export Wizard rather than trying to right click the results and save them.
You can always right-click and select Save Results As, however the resulting CSV file will not contain the column headers! It’s a real pain if you have 50 columns.
Export SQL data to Excel
To export SQL data correctly, right-click the database (not the table) and select Tasks, Export Data.
Next, you need to select a data source. If you right click on the database name, everything should appear automatically.
Now you need to choose your destination. Go ahead and select Microsoft Excel from the dropdown list. After that, you will need to click the Browse button and select a location for the output Excel file. Also, do not forget to check the “First row contains column names” checkbox.
Then you can either export the entire table / view to Excel or write your own query. In my case, I’ll write a custom query for the data I want to export.
Enter your request and then click Analyze to make sure everything is correct.
Finally, click Next and then Finish. Your SQL data will be output to an Excel file and it will include all column headers as well! Enjoy!