Exporting Data from SQL Into an Excel Document
This article explains the methods used to connect to a SQL database and save the contents of a query into Excel for further analysis.
January 3, 2023
AUTHOR(S):
No items found.
Article tags:
No items found.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Share this article
This article is part of THE FOLLOWING SERIES:
Working with Data

This article will assist users in running a SQL query to gather data to place into Excel for further analysis, reporting, or processing. Using this method, you can export many different types of data into Excel assuming you have a valid SQL query and connection details. Please follow the general steps below to export data from your database query to Excel.

  1. (Optional): Download and install the SQL Server Management Studio latest release from the following location:
    https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms

  1. Open SQL Server Management Studio from your Windows desktop.

  1. On the Connect to Server pop-up window, enter the server, user, and password details.

  1. Once connected, locate the query you want to run to pull your data

Note. You may have been provided a .SQL file or you may have the query text stashed elsewhere, it is up to you to identify the appropriate SQL query.

  1. Open the .SQL file using the "Open" option in the "File" menu in SSMS OR click "New Query" in the toolbar and copy/paste in your query.
  1. (Optional): Modify your query with any filter, date, or other changes required.

  1. Highlight/select the portion of the SQL text you would like to execute OR if you want to execute the whole script, highlight/select nothing.

  1. From the toolbar and click on the "Execute" button.

  1. On the "Results" pop-up panel at the bottom, right-click any column header and select "Select All" from the menu.

  1. On the "Results" pop-up panel at the bottom, right-click any highlighted/selected cell and choose "Copy with Headers".

  1. Open a new blank Excel document.

  1. Select any empty cell and hit the Ctrl+A keyboard combination to select all cells.

  1. From the "Home" tab in the ribbon, change the number format from "General" to "Text" in the drop down of the "Number" section
Note. This step is critical to prevent Excel from changing your data (like removing leading zeroes, treating dates as numbers, etc.).

  1. Right-click on cell A1 and choose "Paste" from the menu.

You have now fully exported the SQL results into an Excel document for your further analysis, publishing, or reporting.

Don't miss any update on this topic.
Sign up for our newsletter to receive a personalized collection of our most recent articles, blog posts, videos, and more, curated specifically for you based on your interests.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.