Export SQL query data to Excel
I have a query that returns a very large data set. I cannot copy and paste it into Excel which I usually do. I have been doing some research on how to export directly to an Excel sheet. I am running SQL SERVER 2008 on a server running Microsoft Server 2003. I am trying to use the Microsoft.Jet.OLEDB.4.0 data provider and Excel 2007. I’ve pieced together a small piece of code that looks like this from what I’ve seen in examples.
However this is not working, I am getting an error message saying
«Incorrect syntax near the keyword ‘SELECT'».
Does anyone have any ideas about how to do this or possibly a better approach?
![]()
5 Answers 5
I don’t know if this is what you’re looking for, but you can export the results to Excel like this:
In the results pane, click the top-left cell to highlight all the records, and then right-click the top-left cell and click «Save Results As». One of the export options is CSV.
You might give this a shot too:
Lastly, you can look into using SSIS (replaced DTS) for data exports. Here is a link to a tutorial:
== Update #1 ==
To save the result as CSV file with column headers, one can follow the steps shown below:
- Go to Tools->Options
- Query Results->SQL Server->Results to Grid
- Check “Include column headers when copying or saving results”
- Click OK.
- Note that the new settings won’t affect any existing Query tabs — you’ll need to open new ones and/or restart SSMS.
![]()
If you’re just needing to export to excel, you can use the export data wizard. Right click the database, Tasks->Export data.
I had a similar problem but with a twist — the solutions listed above worked when the resultset was from one query but in my situation, I had multiple individual select queries for which I needed results to be exported to Excel. Below is just an example to illustrate although I could do a name in clause.
The wizard was letting me export the result from one query to excel but not all results from different queries in this case.
When I researched, I found that we could disable the results to grid and enable results to Text. So, press Ctrl + T, then execute all the statements. This should show the results as a text file in the output window. You can manipulate the text into a tab delimited format for you to import into Excel.
You could also press Ctrl + Shift + F to export the results to a file — it exports as a .rpt file that can be opened using a text editor and manipulated for excel import.
How to Import and Export SQL Server data to an Excel file
There are several ways to Export/Import SQL Server data to an Excel file. In this article, a couple of ways to import and export SQL Server data to an Excel file will be explained:
- Export SQL Server data to an Excel file using
- the SQL Server Import and Export Wizard
- T-SQL code
- Export to Excel from ApexSQL Complete
Export SQL Server data to an Excel file using the SQL Server Import and Export Wizard
In SQL Server Management Studio (SSMS), there is a feature that provides for exporting data from one data source to another data source; in this case, data from SQL Server will be copied to an Excel file trough Export Wizard.
To start to use this feature, go to Object Explorer, right click on any database (e.g. AdventureworksDW2016CTP3), under the Tasks, choose Export Data command:

This will open the SQL Server Import and Export Wizard window:

To proceed with exporting SQL Server data to an Excel file, click the Next button. This will open the Choose a Data Source window. On this window, a source from which you want to copy data can be chosen:

From the Data source drop down box, choose the SQL Server Native Client 11.0 item. Under the Server name drop down box, choose the SQL Server instance from which data need to be copied. In the Authentication section, choose the authentication mode for the data source connection and under the Database drop down box, choose the database from which the data will be copied. After all these options are set, click the Next button to proceed.
This will open the Choose a Destination window in which can be specified where to copy data from the data source:

In the Destination drop down box, choose the Microsoft Excel item. Under the Excel file path, choose the destination for copied data from SQL Server data source (SQL Data.xlsx). In the Excel version drop down box, choose the version of the Microsoft Excel worksheet. After these are all set, press the Next button to continue. But after pressing the Next button, the following warning message may appear:
The operation could not be completed.
ADDITIONAL INFORMATION:
The ‘Microsoft.ACE.OLEDB.12.0’ provider is not registered on the local machine. (System.Data)
This happens because SSMS is a 32-bit application and when you launch the Export Wizard via SSMS, it launches a 32-bit version of Export Wizard. On the other hand, the machine (Operating system) on which SSMS is installed is a 64-bit version and the installed SQL Server is a 64-bit version.
To solve this problem, close SSMS, go to the Start menu and find the 64-bit version of SQL Server Import and Export Data:

After launching this SQL Server Import and Export Wizard, it will be prompted with the same window that is used via SSMS. After setting all previous options, click the Next button. The Specify Table Copy or Query window will appear:

On this window, whether to copy data from one or more tables and views or to copy the results of a query can be specified.
Select the Copy data from one or more tables or views radio button and click the Next button. The Select Source Table and Views window allows choosing one or more tables and views from which you want to export SQL Server data to an Excel file by clicking the check box next to the name of the table/view:

As it may be noticed, as soon as the check box next to a table/view is checked, the name of the table/view will be copied under the Destination column. This name represents the name of the sheet where the data from the table will be put, this name can be changed to whatever you like, but for now, it will be left as it is:

To preview which data will be generated to an Excel file, click the Preview button:

After choosing which tables/views data will be copied to an Excel file, click the Next button:

On the Save as Run Package window, check the Run immediately check box and click the Next button:

The Complete the Wizard window shows all options that are chosen for exporting operations. To finalize the process of export SQL Server data to an Excel file, click the Finish button. The last SQL Server Import and Export Wizard window shows the state of the data have been successfully exported or some errors occurred during exporting data:

In our case, the data were successfully generated into the SQL Data.xlsx file in the DimScenario sheet:

Export SQL Server data to an Excel file using T-SQL code
The Transact-SQL OPENROWSET can be used to export SQL Server data to an Excel file via SSMS. In a query editor type and execute the following code:
But, when executing the above code, the following error may occur:
Msg 15281, Level 16, State 1, Line 1
SQL Server blocked access to STATEMENT ‘OpenRowset/OpenDatasource’ of component ‘Ad Hoc Distributed Queries’ because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of ‘Ad Hoc Distributed Queries’ by using sp_configure. For more information about enabling ‘Ad Hoc Distributed Queries’, search for ‘Ad Hoc Distributed Queries’ in SQL Server Books Online.To resolve this error the Ad Hoc Distributed Queries option should be enabled This can be done by using the sp_configure procedure and executing the following SQL code in a query editor:
After executing the above code, the following message will appear that indicate that the show advanced options and Ad Hoc Distributed Queries options are enabled:
Configuration option ‘show advanced options’ changed from 0 to 1. Run the RECONFIGURE statement to install.
Configuration option ‘Ad Hoc Distributed Queries’ changed from 0 to 1. Run the RECONFIGURE statement to install.Now, when again the code is executed:
The following error may appear:
OLE DB provider “Microsoft.ACE.OLEDB.12.0” for linked server “(null)” returned message “The Microsoft Access database engine cannot open or write to the file ”. It is already opened exclusively by another user, or you need permission to view and write its data.”.
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider “Microsoft.ACE.OLEDB.12.0” for linked server “(null)This usually happens because of inadequate permissions.
More about how to resolving these issues can be found in the How to query Excel data using SQL Server linked servers page.
One way for resolving this issue is to open SSMS as an administrator and execute the code again. But this time, another error may appear:
Msg 213, Level 16, State 1, Line 1
Column name or number of supplied values does not match table definition.To resolved this, open excel file (e.g. SQL Data.xlsx) for which is planned to store the data from SQL Server table (e.g. dbo.DimScenario) and enter the column names which will represent the column names from the DimScenario table:

Close the SQL Data.xlsx file and once again execute the code:
Now, the following message will appear:
(3 rows affected)
Finally, the data from the SQL Server table are copied into the Excel file:

Import SQL Server data into Excel using the Data Connection Wizard dialog
Another way to copy data from SQL Server table to an Excel file is to use the Data Connection Wizard dialog from Excel.
In order to achieve that, open an Excel file (e.g. SQL Data.xlsx) in which you want to import data. In the Data tab, under the From Other Source sub-menu, choose the From SQL Server command:

This will open the Data Connection Wizard dialog. In the Server name, enter a name of the SQL Server instance from which data need to be copied. In the Log on credentials section, choose the authentication mode for the data source connection and click the Next button:

From the Select the database that contains the data you want drop down box, choose the database from which the data will be copied. In the grid, all available tables and views will be listed. Choose a desired table / view (e.g. DimScenario) and click the Next button to proceed.

On this window, leave everything as it is and press the Finish button:

In the Import Data dialog, choose the Table radio button, under the Where do you want to put the data? section, choose the Existing worksheet radio button and press the OK button:

After pressing the OK button, the data from the DimScenario table will be copied to the SQL Data.xslx file:

Export SQL Server data to an Excel file using Export to Excel from ApexSQL Complete
Using the Export to Excel feature from ApexSQL Complete, add-in for SSMS and Visual Studio, exporting data from the SQL Server table to an Excel file can be done by one click.
In a query editor, type and execute the following code:
From the Results grid, select data that you want to export to an Excel file, right click in the Result grid and, from the context menu, choose the Export to Excel option:
This will open a new Excel workbook and the selected data from the Results grid will be copied in the first worksheet:

More about exporting to Excel via ApexSQL Complete can be found on the Export to Excel page.
3 Ways To Export an SQL Query to an Excel File using SQL Management server

Export SQL Data to Excel from Microsoft SQL Server
Let’s go over three ways to export an SQL Query to an Excel File Using MSSQL
Despite the pushback from Database aficionados, sometimes it makes sense to export data from SQL to an Excel file. It really depends on who is the audience of the information. Not everyone is great with SQL Analysis. Few people require access to the database.
And lots of times the boss just needs to see the information in Excel.
So, if Excel is the Output required this article is here to help you Export SQL Queries to Excel.
Here are three ways to Export a SQL query to Excel format. The last one can be kind of tricky. I’ll provide a condensed version followed by a detailed version with screenshots.
Three quick ways to Export SQL Data to Excel:
Choose the Summarized Version and then scroll to further down to use the SQL Export Version to Excel that works best for you.
Method Number 1 – Copy Grid results and Paste into Excel
Under Query, Make sure results to Grid are selected.
After Running your query, right-click the top right corner of the grid.
Copy With Headers.
Paste into an Excel FilePossible Issues:
I’ve seen formatting issues with this strategy. For Example, there are situations where the spreadsheet drops preceding zeroes after the copy-paste.I’ve also noticed lengthy fields, (think of a really long free text field) end up running into the next line.
For the reasons above, I prefer this next method for a clean Excel file.
Method Number 2: Export the Query Results as a Task
In the object explorer window, find the database you want to export from.
Right Click the Database, Click Tasks, and Export Data
The Wizard walks you through the rest of the steps but I have included screenshots below.Method Number 3 – Use Good Old fashioned TSQL to send the data to an excel file
For those who value speed above all use the following script format.
Possible Issues – Configuring this might not be your type of fun and getting this straight deserves its own article.
Step by Step instructions with screenshots
Method Number 1 – Copy Grid results and paste into Excel
After ensuring results to grid turned on, Execute your query, right-click the top left-hand corner of the results grid.

Choose Copy with Headers and then you are ready to paste in Excel with Ctrl + C

Method 2 – Export Via the Export Wizard
Right-click on the database you want to export from. Then Select tasks and “Export Data”.

The SQL Server Wizard will startup. Click Next through the prompts.

Select the appropriate Native client, your server name, and database and choose “Next”.

Next, Select Microsoft Excel and the file path where you want to import the data. The .xls file that you name will be created by this process.

Now you can choose to export a whole table or a query. For the purpose of this exercise, we are creating a query.

Paste the query into the SQL Statement field. Make sure every output field has a unique name.

Click Next on the “Select Source Tables and Views” screen.

I use the default settings on the “conversion issues and data type mapping screen”

Now you can choose to Run immediately or Save an SSIS Package for later reuse.

Double Check your settings and click finish.

Make sure there were no errors in the Export.

Now Go to the directory you choose earlier and make sure you have a sweet-looking Excel File at that location!

Method Number 3 – Use TSQL to send the data to an excel file
This method is the quickest once you get it set up but the configuration is the tricky part. Permissions can be a limiting factor.
Also with the script below, you have to make sure the file exists before you run the query for it to import properly.
How to Export SQL Data to Excel and Update the Export Automatically
%20-%20Stephanie%20(normal).png)
— WHAT YOU’LL LEARN: Everything you need to know (and nothing you don’t) on how to export SQL data to Excel and update the export automatically (with any SQL database: MySQL, Microsoft SQL Server, PostgreSQL).
— YOUR TAKE-AWAY: Save hours of doing the exact same process over and over again.⌚
— WHO IS THIS TUTORIAL FOR? Anyone spending way too much time copy-pasting data from a SQL database into Excel. BONUS: Save your cheat sheet at the end for future reference.How To Export SQL Data to Excel and Update the Export Automatically?
It's a 4-steps process:
- Connect Excel to an external data source: your SQL database
- Import your SQL data into Excel
- Create a Pivot Table with an external SQL data source
- Automate Your SQL Data Update In Excel With The GETPIVOTDATA Function
Let's get to the details on how to implement those step in this tutorial to save you hours in the future!

Connect Excel to an external data source: your SQL database
If you work on a Mac and you experienced difficulties connecting your SQL database, I’d like to tell you that I share your pain. I’ve been through it too… only to realize that there is kind of a bug on Excel for Mac ♀️ (to be precise, I work on Microsoft Excel for Mac version 16.33). The good news is: I have the solution to your problem!
If you want to learn how to connect Excel to your SQL database with a Mac in order to query data from your SQL database into Excel, read the following lines.
#1 Install An ODBC
You need an ODBC (Open DataBase Connector) to load data from a SQL database to Excel. In order to do so on Mac, you need to install an interface to manage ODBC configuration files. I’ve used ODBC Manager for instance. ODBC Manager is a Mac OS utility application that configures ODBC data sources such as Microsoft Excel. Mac OS used to include an ODBC Administrator utility but Apple stopped including the ODBC Administrator with Mac OS starting with the release of Mac OS X "Snow Leopard". ODBC Manager was developed as a replacement for ODBC Administrator.
#2 Install A Driver
You have to install a driver for your SQL database. For instance, I’m using MySQL so I installed the MySQL driver for Mac. You can download here the Microsoft ODBC Driver for SQL Server. Click here for the official PostgreSQL ODBC Driver.
#3 Avoid A Common Error
Here might be the part where you struggled if you tried it by yourself. At least I did. To make it work, you need to move the SQL driver folder from /usr/local/ to /Library/ODBC/.
Why? Because the driver gets downloaded to /usr/local but Excel Microsoft Office is a sandboxed application, so it doesn't have access to /usr/local. Therefore, Excel doesn't know how to fetch the config file in the right place.
How did I figure this out? It happened after having wasted tons of time, growing increasingly frustrated and feeling totally stuck with the following error message:
![Error message: IM003 [iODBC][Driver Manager]Specified driver could not be loaded](https://global-uploads.webflow.com/5f8b0a1abe69652278dad51c/5f917b0d42807526121b2935_5e38b6df4e10bc5de30f62fd_3agSvMDvpGV6ie7P_RZzMF1vJf2nm6FYEDvlWQu0xi-P-Fn4NhYg9bUz8wusUvygURK3-6RF-iJbsWu5lcsXmKVekpSq1HorkHv-zKDwmiYpv7gYAo9UfQWEXIQZHLOZAlV9KPz_.png)
If you got that one too, you know what I’m talking about! Help came from Stack verflow . I would never have guessed it and discover that many other people spent half a day looking for a solution. So here is the explanation for you to save time and move your MySQL ODBC driver to /Library/ODBC/:
- Copy the driver's whole directory /mysql-connector-odbc-8.0.12-macos10.13-x86-64bit to /Library/ODBC
- Update the file odbc.ini, also located in /Library/ODBC/, with the driver's new location.
#4 Create a DSN
You have to create a DSN (Data Source Name) config using the SQL driver in ODBC Manager and fill in the database connection information.
To configure a Connector/ODBC DSN on macOS, you can either:
- Use the command-line utility (myodbc-installer)
- Edit the odbc.ini file within the Library/ODBC directory of the user
- Use the ODBC Administrator GUI
- NB: The ODBC Administrator is included in OS X v10.5 and earlier but users of later versions of OS X and macOS need to download and install it manually
To create a DSN using the myodbc-installer utility, you only need to specify the DSN type and the DSN connection string.
- With Connector/ODBC 8.0:
shell> myodbc-installer -a -s -t"DSN=mydb;DRIVER=MySQL ODBC 8.0 Driver;SERVER=mysql;USER=username;PASSWORD=pass"
- With Connector/ODBC 5.3:
shell> myodbc-installer -a -s -t"DSN=mydb;DRIVER=MySQL ODBC 5.3 Driver;SERVER=mysql;USER=username;PASSWORD=pass"
To use ODBC Administrator:
- Before you start, make sure you are well set up:
- For correct operation of ODBC Administrator, ensure that the /Library/ODBC/odbc.ini file used to set up ODBC connectivity and DSNs are writable by the admin group. If this file is not writable by this group, then the ODBC Administrator may fail, or may appear to work but not generate the correct entry.
- Some issues with the macOS ODBC Administrator and Connector/ODBC may prevent you from creating a DSN using this method. In that case, use the command line or edit the odbc.ini file directly. Existing DSNs or those that you created using the myodbc-installer tool can still be checked and edited using ODBC Administrator.
- Then, in the Applications folder, open the Utilities folder and click on the ODBC Administrator:

- This will open your ODBC Administrator dialog box. Here is my ODBC Administrator dialog with the System DSN tab open. As you can see, I’m working with MySQL but you can as well work with Microsoft SQL Server or PostgreSQL. This tab includes Add, Remove, and Configure options. Additional tabs are User DSN, Drivers, Tracing and Connection Pooling:
- From the ODBC Administrator dialog box, choose either the User DSN or System DSN tab and click Add. It will open a dialog box asking you to choose a driver, here is how it looks like:

- Select the Connector/ODBC driver and click OK:

- You will be presented with the Data Source Name (DSN) dialog box. Here is my ODBC Administrator Data Source Name dialog box:

7. Enter the Data Source Name. Here, I named it “Sample”:

8. Enter the optional Description for the DSN. Here, I named it “Connection to sample my Sample database”. You can skip this step if you want:

9. Click Add to add a new keyword/value pair to the panel. You need to configure at least four pairs to specify the server, username, password and database connection parameters (further resources here on Connector/ODBC Connection Parameters):

10. Here will appear a first pair, set by default to “Keyword” and “Value”:

11. To modify its value, simply double click on “Keyword” to change it:

12. Here I want my first pair to be server=mysql so I replace “Keyword” by “server”:

13. And then double click on “Value”:

14. I replace here “Value” by ”mysql” and I click Add:

15. Another line set with “Keyword” and “Value” as default values will appear. I repeat the same process to setup my second keyword/value pair: user=sakila, click Add ; I continue with my third keyword/value pair: password=Sample, click Add ; and I finish with my fourth and last keyword/value pair: database=test_world, and finally click OK:

16. Hereunder is how my completed DSN configuration looks like with Data Source Name, Description and key=value pairs:

17. Click OK to add the DSN to the list of configured data source names and you’ll get a new line with you new DSN:

Import your SQL data into Excel
#1 Click Where You Want Your Pivot Table
Now that you connected Excel to your SQL database, you’ll be able to query data from your SQL database directly into Excel using the pivot table feature, without needing to copy-paste it. Position yourself on a new worksheet in the cell where you want to insert your pivot table. We clicked on cell A1 here:


#2 Click Insert

#3 Click Pivot Table
A Create Pivot Table dialog box will open:

#4 Click Use an external data source, then Choose Connection

This will open the iODBC Data Source Chooser dialog box on the User DSN tab.
#5 Click on the System DSN tab

You will see the list of your System Data Sources:

#6 Select the DSN created in ODBC Manager
If needed, remember you can refer to the first part of this tutorial entitled “Connect Excel to an external data source: your SQL database”.

#7 Fill the requested username and password

#8 Avoid a Common Error
It’s quite common to get an error message at this point so, if it happens to you, no worries, we’ll cover it (otherwise, you rock, congrats for getting it to work on the first try ). Here is the error message I had for instance > “Alert [MySQL][ODBC 8.0(a) Driver]Unknown MySQL server host ‘Value’ (0)”:

This means that my host value had a wrong configuration. So I checked my dialog box and, indeed, it appeared that I had been forgetful when configuring my first keyword/value pair to the Data Source Name dialog box: I forgot to change the default “Value”:

So I quickly corrected this oversight and clicked OK.
#9 Access The Microsoft Query Dialog Box
When Excel correctly connects to the MySQL server, the Microsoft Query dialog box opens:

Let’s have a closer look at the box here:

#10 Click on the arrow to see the list of tables in your database

#11 Select the table you want to query data from your SQL database into Excel
Only one table at a time should be selected in the SQL Statement. Once selected, the following query will automatically be created: “SELECT * FROM [table_name] ;”. If you know about SQL, you can also write your own custom SQL query here.

#12 Click on Return Data when you’re done with your selection
You’ll be brought back on the Create Pivot Table dialog box. Click on the OK button to get back to the pivot table:


Create a Pivot Table with an external SQL data source
#1 Discover Your Pivot Table Fields
At the end of the second part of this tutorial where you imported your SQL data into Excel, you get an empty pivot table with Pivot Table Fields on the right hand-side so that you can show the fields you want and rearrange them to create your own layout:

Here is a closer look at my PivotTable Fields, coming from my SQL database:

#2 Drag A Field To The Rows Area
In order to build your pivot table, drag a field from the field section to an area in the areas section underneath, Columns, Rows or Values.
Here, I’d like to create a pivot table to show the Quarterly Revenue per Product. It means that I will need the list of products as rows, the quarters as columns and the revenues as values.
So I first dragged Product from the field section to the Rows area:

#3 Drag A Field To The Columns Area
Then, the Quarter from the field section to the Columns area:

#4 Drag A Field To The Values Area
Finally, the Revenue from the field section to the Values area:

Here is a closer look:

Congrats on building your pivot table!
One question though: would you share the table as is? As for me, I deeply thank Microsoft engineers for having come with such a powerful tool for turning thousands of records of detailed data into a concise summary in a few clicks. But sorry folks, I don't share the same aesthetic tastes.
Hereafter, I’ll show you how to transform this powerful-but-ugly pivot table and then use the GetPivotData function to populate a great-looking dashboard.

Automate Your SQL Data Update In Excel With The GETPIVOTDATA Function
You’re in the right place if you want to learn how to update your great-looking dashboard automatically.
After this tutorial, never again you will have to painfully recreate pivot tables every week only to get results that you can format in a beautiful way.
Now, when new data will be added to your data set, you’ll refresh the pivot table, and your great-looking dashboard will automatically get new data from the pivot table, with a perfectly formatted report, ready to share and print.
#1 Build Your Final Dashboard Structure
On a new worksheet, build your perfectly-looking report with no value inside.
Here is my initial pivot table:

And here is how I would rather present my data to my team:

#2.1 Try A Dashboard With Breakable Formulas
What I initially thought I would do (and it would work as long as I didn't change anything) is that I would just hit an equal sign and then come over to the pivot table, left click in cell, hit enter:

And there you go, you have the dollar value that matches here:

Then, I could take my mouse, go into the lower right hand corner of the cell that I’ve selected until it becomes a plus sign, hold my left mouse key, and drag it down. I’d have all of these values coming up:

If that's what I wanted, and I’d never change this pivot table, then I’d be fine, and just leave it like that. But, because this pivot table is dynamic, it’s going to break these formulas.
#2.2 Build a Robust Dashboard That Will Automatically Update
Luckily, we don’t have to worry as there’s a way to get around these broken formulas, and it’s precisely what we’re going to explain here. You’ll learn how to specify the value you want to return from the pivot table using the function GETPIVOTDATA.
I have to admit I was a bit puzzled by the function syntax the first time I was trying to determine the arguments I should use. FYI, here is the official syntax:
GETPIVOTDATA(data_field, pivot_table, [field1, item1, field2, item2], . )
One solution you could use, which is the easiest one but that I do NOT recommend to implement as it ends up taking way too much time, is to type =GETPIVOTDATA and click on the cell you want to retrieve data from. You will get the correct data but it won’t let you reuse the formula for other cell, forcing you to manually enter each cell data. Here the formula Excel automatically proposed to me when I typed =GETPIVOTDATA and selected the corresponding cell in the pivot table:

The problem here is that, if I take my mouse, go into the lower right hand corner of the cell that I’ve selected until it becomes a plus sign, hold my left mouse key, and drag it down. I’d have all of these values coming up:

Mmm… not very interesting. Why is that? Because I didn’t lock the field and item that are used by the function.
I had to go through a bunch of elliptical tutorials and felt no one was really clear. So I’d like to make it easy for you, and I believe that a graph is definitely the most simple way to understand how to write you GETPIVOTDATA function. Here is how:

So here is the syntax detailed description for you to fully grasp it:
The function syntax by the book:
GETPIVOTDATA(data_field, pivot_table, [field1, item1, field2, item2], . )
The function used in our example, where it returns the quarterly revenue per product from a pivot table:
The GETPIVOTDATA function syntax has the following arguments:

Now that we wrote the function in a way that will allow us to work faster, let’s click on the cell with the GETPIVOTDATA function, go into the lower right hand corner of the cell until it becomes a plus sign, hold my left mouse key, and drag it down. I’d have all of these values coming up:

Yes! That’s what I wanted! . I do the same dragging it towards the right and I’m done:

Does your GETPIVOTDATA return the #REF! error value?

It might be for one of these reasons:
- The pivot_table argument is not a range in which a PivotTable is found.
- The arguments do not describe a visible field.
- The arguments include a report filter in which the filtered data is not displayed.
You can add a chart if you like:

#3 Refresh Your SQL to Excel Dashboard In 1 Click
Now, let’s test the automation of our table and ensure it updates if we change the data in our SQL database. So here is the initial data of my pivot table and the associated great-looking dashboard and chart:



Now, in my SQL database, I’ll boost the “Confidence Coaching” revenue in Q4 to $10,200. Let’s see how easy it is to automatically update the data in Excel. I click on Refresh all:
And boom, everything is refreshed in one click :



You can keep your dashboard data up to date by refreshing the link to its source. Each time you refresh the connection, you see the most recent data, including anything that's new or has been deleted.

Your Cheat Sheet
Save your cheat sheet for future reference: bookmark it, download it and share it with others who might also need it.

Last thoughts: try this new tool
The reason you want to push MySQL data to Excel is probably because you want to make this data accessible to team members who are confortable in a spreadsheet but maybe not confortable with SQL or with a Business Intelligence tool.
If that's the case, you should definitely try out Actiondesk. Actiondesk is the easiest way for startup teams to make better decisions with their data. You can access your company key data without code or writing SQL, you'll just need basic spreadsheet skills.
Actiondesk looks like a spreadsheet and works like a spreadsheet. Users used to Google Sheets and Excel will be able to learn Actiondesk very fast.
If you're looking for a more solid solution, check out Actiondesk, you can try it for free.