How to Connect Excel to SQL Server in 3 Easy Steps

Written by Andy McDonald
Reviewed by Johannes Åkesson
Last updated
8 min read

In a previous article, we spoke about why you need both Excel and SQL in your data management solutions, but how do you connect Excel to SQL Server?  You can connect Excel to SQL Server in three simple steps using the SQL Spreads Excel add-in: get your connection details, connect to SQL Server, and load a table into Excel.

In this article, we’ll walk you through each step and show you how to edit the data directly in Excel and save your changes back to SQL Server.

But, first, we’re going to re-cap the benefits of connecting Excel to data in SQL Server.

Benefits of connecting Excel to SQL Server

To demonstrate the benefits of connecting Excel to SQL Server, let’s look at an example.

This spreadsheet is used by Sales Reps at a manufacturing company to prepare quotes for customers.  Each Sales Rep has a copy of the spreadsheet, which includes a list of inventory items and their prices.  The list of inventory items and prices is extracted from the finance system by an administrator.  The quote sheet uses some data validation lookup formulas to retrieve the prices when a Sales Rep selects an item from the dropdown.

An Excel quotation template whose item drop-down and price lookup read from a product list

This works well until the organization needs to update the prices. In which case, each user would need to copy and paste the new pricing into the spreadsheet (or use a new copy of the spreadsheet).  Also, when the Sales Rep creates the quote, they don’t know whether the items are actually in stock.

A better solution would be to connect the Excel spreadsheet to the inventory table in the finance system database.  Each time the Sales Rep opens the quote spreadsheet, they are refreshing the price data from the live database.  We can go one step further and make the connection to the database also bring back the current stock levels so that quotes can be prepared for items actually in stock.

So, to summarise, the benefits of connecting Excel to SQL Server are:

  • we have access and can view up-to-date information
  • we are using one single, trusted data source
  • we can perform on-the-fly analysis or aggregation of the source data using simple Excel functions like pivot tables

Connect Excel to a SQL Server database : 3 easy steps

The easiest way to connect Excel to a SQL Server database is with SQL Spreads.  SQL Spreads is a simple Excel add-in.

The SQL Spreads download can be found here, and the installation process is described here.

Step 1: Gather the database connection details

You’ll need the following information to connect Excel to SQL Server, so get the details as the first step:

  • SQL Server Name
  • Database Name
  • Table or View that contains the information you need
  • Login details (if not using Windows authentication)

The form of the SQL Server Name will depend on whether SQL Server is installed locally, on a network, or a remote location (note that this is the same name as when you connect to SQL Server in SQL Server Management Studio).

Typical server name Case
Localhost When SQL Server is installed locally
localhost\sqlexpress When SQL Server Express is installed locally
servername, or servername\instancename When SQL Server is installed on a server in your company network
IP-address When SQL Server is installed in a remote location
yourserver.database.windows.net When you use Azure SQL Database

Step 2: Connect to SQL Server

Once SQL Spreads is installed, you’ll see it as a new ribbon tab; go here and click the Open Designer button.

The SQL Spreads tab in the Excel ribbon, with the Design Mode button highlighted

In the SQL Spreads Designer panel on the right side, click the Edit button to open the SQL Server connection dialog.

The SQL Spreads Designer panel, with the Edit link next to the document’s SQL Server connection

Enter the name of your SQL Server into the SQL Server name field:

The SQL Spreads Connect to Microsoft SQL Server dialog, with localhost entered as the SQL Server name

Select if you should connect using your Windows login (Windows Authentication), enter a user name and password (SQL Server Authentication), or sign in with a Microsoft Entra ID work account (Azure AD Authentication, on the Pro plan and above). Windows and Azure AD authentication are the more secure options (see here for more information).

The SQL Spreads Connect to Microsoft SQL Server dialog, with the Windows Authentication and SQL Server Authentication options

Click OK. SQL Spreads will try to connect to the database. If the connection is successful, your databases will show up in the SQL Spreads Designer panel.

The Database tab of the SQL Spreads Designer, listing the databases on the connected SQL Server

Step 3: Select the relevant table in SQL Server

Now that we’ve created the connection from Excel to SQL Server, we can select which table of data we want to use in Excel.

In the SQL Spreads Designer, click on the database and then select your table.

The SQL Spreads Designer with a database expanded to show its tables

As soon as you select a table, the data in the table is populated in the Excel sheet.

You can now see all the data in your SQL Server table and use it in your Excel workbook.  The real power with SQL Spreads is the ability to update the data in the table in SQL Server direct from Excel.  For example, I can update the prices in the product table directly in Excel, and save the changes back to SQL Server!

A SQL Server table loaded into Excel with SQL Spreads, with a changed value and the Save to Database button marked

Before anything is written to SQL Server, SQL Spreads asks you to confirm the changes. You also decide who can change what: with the Designer role, you choose which columns a user with the Data Editor role can see and edit, and values are checked against the table’s data types as they are entered.

Example: A simple Quote form in Excel connected to SQL Server

Let’s go back to our earlier example of the quote form and the inventory list.  We’re going to change this so that the quote form gets its data from the table in the SQL server instead of a static list in the spreadsheet.

If you want to follow along with this example, you’ll need to have access to the AdventureWorks sample database, which you can get from here.   

First, we’re going to create a new sheet in the quote_sample workbook and leave it with the default name of Sheet2 – the data from SQL Server will be populated here.

A blank new sheet named Sheet2 in the quote workbook, next to the Quotation and Product sheets

Next, we’re going to connect to the AdventureWorks database using the steps outlined above.

Step (1) : Connection details

Here are the connection details I’m going to use to connect to my SQL Server database:

  • SQL Server Name: Andy\SQLExpress
  • Database Name: AdventureWorks
  • Table or View: Production.Product
  • Login details: Windows authentication

Step (2): Connect to SQL Server

We want to connect to the Product table in SQL Server and populate the ‘Product’ sheet in the quote worksheet. To do this we click on SQL Spreads > Open Designer and enter the connection details and expand the correct database (in our case, AdventureWorks) so that we can select the relevant table (in our case, Production.Product).

The SQL Spreads Designer connected to a SQL Server Express instance, listing the AdventureWorks database

 

Step (3): Select the Production.Product table in SQL Server

Click on the Production.Product table in the list and the data is automatically populated into the Product sheet.

The AdventureWorks Production.Product table loaded into Excel with SQL Spreads, with the table selected in the Designer

We can now use this data as the source for our lookups in the Quote template, but before we do, we’re going to look at how to filter the data returned from SQL so that only in-stock items are displayed.

Click on the Filters tab in the SQL Spreads Designer.  Under the Filter Type option, we can select ‘Column’ or ‘Custom SQL’.  We’re going to select ‘Custom SQL’ because we need to run a SQL query that will return only items in stock, and that means we need to join the Product table to the ProductInventory table.

The Filters tab in the SQL Spreads Designer, with Custom SQL chosen as the filter type

When you click the ‘Custom SQL’ option, a text box is displayed where you can enter the SQL query.  For our use case, we want to return a list of products via a join query, we’ll need to use a Sub Query.  So, we need to paste the following:

Name  in (SELECT P.Name AS Product
FROM AdventureWorks.Production.Product AS P
JOIN AdventureWorks.Production.ProductInventory AS PI ON P.ProductID = PI.ProductID
JOIN AdventureWorks.Production.Location AS L ON PI.LocationID = L.LocationID
where L.Name = 'Finished Goods Storage' AND PI.Quantity > 0
GROUP BY P.Name, P.ListPrice)

in the Custom SQL box:

A Custom SQL filter in the SQL Spreads Designer that limits a product list to items in stock

When you click ‘Save’, the data in the Product table is reduced to the filtered records. Finally, we’re going to update the named range that was used by the data validation lookups in the Quote sheet:

Excel’s Name Manager with the product_name range, which needs to point at the table loaded from SQL Server

And, we also need to update the XLOOKUP function that the Quote sheet uses to get the price when a user selects an item – it needs to reference the new Table2 which is the data from SQL Server.

The XLOOKUP arguments for the quote sheet’s price lookup, which need to point at the table loaded from SQL Server

 

That’s it!  Our Sales Reps can now create quotes based on up-to-the-minute prices for items that are currently in stock.  Each time the Sales Rep opens the spreadsheet, the data will be refreshed from SQL Server.

Bonus Feature!  Update prices in Excel and save to SQL Server

We have connected Excel to SQL Server so that our Sales Reps can create quotes based on up-to-the-minute prices and availability.

We can go one step further and provide the ability for a designated user (eg an Administrator) to update the Sales Prices of the items directly in Excel, and have the updates saved back to the ‘Production.Product’ table in SQL Server.

For example, if I wanted to change the price of the first item in the list to $39.99, I can type in the ListPrice cell and click ‘Save to Database’ – it’s that easy!  Of course, we would want this capability locked down to certain users only, and this is easily done through SQL Spreads.

The SQL Spreads dialog asking the user to confirm saving one modified row before anything is written to the database

Customers use this for exactly this kind of job. The system and IT manager at a tire retreading company, who updates prices on 50,000 to 60,000 articles in the company’s ERP database, used to pay a consulting firm to update each price list:

“Just to buy the license one year was cheaper than updating prices one time with consultants.”
System and IT Manager, tire retreading company

Common connection errors

“A network-related or instance-specific error occurred while establishing a connection to SQL Server.” SQL Server could not be reached at the name you entered. A common cause is a firewall that blocks the connection between your computer and the server, so ask IT to check that the SQL Server port (1433 by default) is open. Also check the server name, including the instance name if there is one, such as servername\instancename, that the SQL Server service is running, and that TCP/IP is enabled for the instance in SQL Server Configuration Manager.

“Login failed for user.” The server was found, but the sign-in was refused. With SQL Server Authentication, check the user name and password, and that the server accepts SQL Server logins. With Windows Authentication, check that your Windows account has access to the database.

Summary

In this article, we’ve shown how easy it is to connect Excel to SQL Server using the SQL Spreads Add-In.  We also went through an example to show how a simple quotes spreadsheet can use up-to-date sales price data from a SQL database, and how the prices in the database can also be updated directly from Excel.

Download the trial version of SQL Spreads and connect Excel to SQL Server today.

The trial is free for 14 days, and no credit card is needed. After that, SQL Spreads starts at $39 a month for a Designer and $19 a month for a Data Editor, billed annually. Other plans and monthly billing are on the pricing page.

FAQs

Can I edit SQL Server data in Excel and save it back?

Yes. With SQL Spreads, the sheet stays connected to the table: you edit the data in Excel, confirm, and the changes are written to SQL Server.

How do I connect Excel to SQL Server with Windows authentication?

In the SQL Spreads connection dialog, enter the server name and select Windows Authentication. SQL Spreads connects as the Windows account you are signed in with, so there is no separate password.

How do I get the latest data from SQL Server into Excel?

Click Refresh from Database in the SQL Spreads ribbon. The data also refreshes automatically each time the document is opened.

Does SQL Spreads work with Azure SQL?

Yes, on every plan. Signing in with Microsoft Entra ID (Azure AD) authentication needs the Pro plan or higher.

 

Related Articles

Try SQL Spreads for free

Try SQL Spreads during 14 days for free. The free trial is the fully
functional, time-limited only product.
Try Excel Add-In for Free
Five stars
14-days Free Trial. No credit card required.
×