Read Data from SQL Server (Database Connection)

Read data from SQL Server in Excel tutorial showing database connections Power Query SQL queries and data refresh
Connect Excel directly to SQL Server and work with live database data. This tutorial explains how to create a SQL Server connection, authenticate securely, import tables or custom queries, transform data with Power Query, refresh connections automatically, and build reports from database records. Ideal for analysts, database administrators, developers, finance teams, and business professionals who need to analyse SQL Server data in Excel.

Someone emails you a CSV export from the company database every morning, and by lunchtime it is already out of date. Meanwhile the real data sits in SQL Server, current to the second, just out of reach. Power Query closes that gap. It connects Excel directly to SQL Server, pulls exactly the rows and columns you specify, and rebuilds the result on demand with a single Refresh. No more waiting for exports, no more stale CSVs, and no SQL expertise required to get started — though a little SQL knowledge unlocks a lot more power.

This guide covers the full connection process, the crucial difference between importing a whole table and writing a targeted query, how query folding keeps large pulls fast, and six practical patterns from a simple table load to parameter-driven reports.

What You Need Before Connecting

A SQL Server connection needs three pieces of information and one permission. Gather these before you start and the connection takes under a minute. Miss one and you will be stuck at the credentials screen. Your database administrator can supply all of them if you do not already know them.

The connection checklist: 1. SERVER NAME e.g. SQLPROD01 or sqlprod01.company.com,1433 (may include an instance: SERVER\INSTANCE or a port ,1433) 2. DATABASE NAME (optional at connect time, but recommended) e.g. SalesDW 3. AUTHENTICATION METHOD • Windows — uses your logged-in account (most common on a domain) • Database — a separate SQL username + password from your DBA • Microsoft account / Azure AD — for cloud-hosted Azure SQL 4. PERMISSION Your account (or the SQL login) needs at least SELECT/read rights on the tables you want. Power Query reads data; it does not need write access for reporting.
Read-only is enough — and safer. For reporting you only ever need SELECT permission. Ask your DBA for a read-only login rather than a full-access one. Power Query never writes back to the database when you refresh a query, so read access covers every scenario in this guide.

Making the Connection — Step by Step

The connection wizard is short. Once you enter the server and choose how to authenticate, Power Query remembers the credentials so future refreshes are silent. These steps create the connection and open the Navigator, where you pick what to load.

1.
Go to Data > Get Data > From Database > From SQL Server database.
2.
Enter the Server name. Optionally enter the Database name to jump straight to it. Leave the SQL statement box empty for now.
3.
Choose the authentication tab — Windows for your domain account, or Database to type a SQL username and password. Click Connect.
4.
In the Navigator, expand the database and tick the tables or views you want. Click Transform Data to shape them, or Load to drop them straight onto a sheet.

Import a Whole Table vs Write a Query — Choose Wisely

This single decision shapes performance more than any other. Loading an entire table is easy but can drag millions of rows into Excel that you will never use. Writing a targeted query — or filtering in Power Query so the work pushes back to the server — returns only what you need. Understanding the trade-off up front prevents a slow, bloated workbook later.

Two ways to pull SQL data: OPTION A — Navigator picks the whole table Easiest. But "Orders" with 8 million rows loads all 8 million, even if you only report on last month. Slow to refresh, heavy file. OPTION B — Filter/shape in Power Query (recommended) Load the table, then add filter/remove-column steps. If those steps "fold" (see next section), SQL Server does the filtering and returns only matching rows. Fast and light. OPTION C — Write a native SQL query at connect time In the connection dialog, expand "Advanced options" and type: SELECT OrderID, OrderDate, Amount FROM Orders WHERE OrderDate >= '2025-01-01' Returns exactly those columns and rows. Maximum control. Rule: prefer B for most work; use C when you know the SQL and want precise control or a join across several tables.

Query Folding — Why Your Filters Should Push to the Server

Query folding is the feature that makes Power Query on SQL Server fast. When your steps can be translated into a single SQL statement, Power Query sends that statement to the server and lets the database do the heavy lifting. The server returns only the final, filtered result. Break folding, and Excel is forced to download everything and process it locally — which is dramatically slower on large tables.

Folding in action: YOU DO (in Power Query): SERVER RECEIVES (folded SQL): Load Orders table SELECT * FROM Orders Filter Region = "East" → WHERE Region = 'East' Remove 6 columns → SELECT (only kept columns) Keep top 1000 → TOP 1000 → SQL Server runs ONE efficient query, returns ~1000 rows. FOLDING BREAKS when you add a step SQL cannot express, e.g.: • certain custom columns with complex M functions • merging with a non-database source (a local Excel table) • some text operations and index-based steps Check folding: right-click a step > "View Native Query". If it is greyed out, folding stopped AT that step — everything before it folded; everything after runs locally in Excel. Golden rule: put your row filters and column removals EARLY, while folding is still active, so the server shrinks the data first.
Filter first, transform later. Order your steps so that anything reducing rows or columns comes before anything that might break folding. That way the server hands back a small dataset, and only the final polish happens in Excel. Reordering steps for folding is often the single biggest refresh-speed win on a slow query.

Example 1: Load a Single Table and Refresh Daily

The simplest useful pattern connects to one table or view and keeps it current. A "vSalesSummary" view built by your DBA is ideal — it already contains the right columns, so you load it and set it to refresh when the file opens. From then on, opening the workbook shows today's numbers with no manual export anywhere in the process.

Load-and-refresh pattern: From SQL Server database → Navigator → tick vSalesSummary → Load Set it to auto-refresh: Data > Queries & Connections > right-click the query > Properties ✓ Refresh data when opening the file ✓ Refresh every 60 minutes (optional, while open) Result: the workbook shows live figures each time it opens, pulling straight from the database view — no CSV, no export.

Example 2: Filter to Last 90 Days So Folding Shrinks the Pull

A transactions table with millions of rows should never load in full for a recent-activity report. Adding a date filter that folds means SQL Server returns only the last 90 days. Specifically, the filter becomes a WHERE clause on the server, so the network only ever carries the rows you actually need rather than the entire history.

A folding date filter: 1. Load the Transactions table (do NOT expand or transform yet). 2. Click the OrderDate column filter → Date Filters → After... or use a relative filter for the last 90 days. 3. Right-click the filter step > View Native Query to confirm: SELECT * FROM Transactions WHERE OrderDate >= DATEADD(day, -90, GETDATE()) Because the WHERE clause folded, the server filters millions of rows down to the recent subset and sends back only those. Refresh time drops from minutes to seconds.

Example 3: A Native SQL Query with a JOIN Across Tables

When the data you need spans several tables, a native SQL query joins them on the server and returns a single tidy result. This is far more efficient than importing three tables and merging them in Excel. The join runs where the data lives, using the database's indexes, and only the combined output travels to your workbook.

Native query with a JOIN (Advanced options box): SELECT o.OrderID, o.OrderDate, c.CustomerName, c.Region, o.Amount FROM Orders AS o INNER JOIN Customers AS c ON o.CustomerID = c.CustomerID WHERE o.OrderDate >= '2025-01-01' ORDER BY o.OrderDate DESC; Paste this into: From SQL Server database > Advanced options > SQL statement. The server executes the join and returns one flat, report-ready table. Excel never sees the separate Orders and Customers tables — only the joined result, already filtered and sorted.
A hand-written native query stops folding. When you supply your own SQL statement, Power Query treats it as fixed and will not fold additional steps back into it. That is fine — you already wrote an efficient query. Just make the SQL itself do the filtering and joining, since later Power Query filters on top of a native query run locally in Excel rather than on the server.

Example 4: Parameter-Driven Reports — One Query, Many Regions

A report that should show one region at a time does not need a separate query per region. A Power Query parameter lets a single query switch its filter based on a value you control. Change the parameter from "East" to "West" and refresh, and the same query returns the other region. This turns one connection into a flexible, reusable report.

Parameter-driven filtering: 1. Home > Manage Parameters > New Parameter Name: SelectedRegion Type: Text Current Value: East 2. Load the table, filter the Region column, then in the formula bar replace the hard-coded "East" with the parameter name: = Table.SelectRows(Source, each [Region] = SelectedRegion) 3. To change the report: Home > Manage Parameters > set SelectedRegion to "West" → Refresh. Same query, new region. Bonus: drive the parameter from a worksheet cell so a dropdown on the sheet controls which region the query returns.

Example 5: Connect to a View Instead of Raw Tables

Database views are pre-built queries stored on the server, and they are often the cleanest thing to connect to. A DBA can create a view that joins tables, applies business rules, and exposes exactly the columns reporting needs. Connecting to the view rather than raw tables means the complex logic lives in one maintained place, and your Excel query stays simple and stable even when the underlying tables change.

Why connect to a view: Raw tables: Orders, Customers, Products, Regions, Reps... → you must join and clean them yourself, every time. A view (vSalesReport) built by the DBA: → already joined, already cleaned, already filtered to the columns and rules the business agreed on. In Navigator, views appear alongside tables. Tick the view, Load, done. If the DBA later adds a column or fixes a join, your workbook benefits on the next refresh with no rework. Views also shield your report from table restructuring — the view keeps its shape even if the tables behind it change.

Example 6: Combine SQL Data with a Local Excel List

Sometimes you need to enrich database data with something that only lives in a spreadsheet — a manual target list, a set of category labels, or a small mapping table. Merging a SQL query with a local Excel table does exactly this. Note that the merge itself runs locally in Excel and breaks folding, so filter the SQL side as much as possible before the merge to keep the database portion fast.

Blend server data with a local table: Query 1 (SQL): monthly actuals per region (folded, small) Query 2 (Excel): a Targets table typed on a worksheet Merge: Home > Merge Queries Match Query 1.Region to Query 2.Region Expand the Target column into the result. Now each region row carries both its SQL actual and its Excel target, ready for a variance column: actual − target. Because the merge runs in Excel, keep the SQL side lean first: filter and aggregate on the server, THEN merge the small result with the small local list.

Troubleshooting SQL Server Connections

All three problems below are the most common connection issues. Each has a clear cause and a specific fix.

Cannot connect — the server is not found or times out

A "server not found" error usually means the server name is wrong or the machine cannot reach the database. First, double-check the exact server name with your DBA, including any instance name after a backslash or a port after a comma. Second, confirm you are on the corporate network or VPN, because most database servers are not reachable from outside. Third, a firewall may be blocking the connection port (1433 by default for SQL Server). If the name and network are correct but it still times out, ask your DBA whether your account is allowed to connect from your location.

The refresh is extremely slow or downloads far too much data

Slow refreshes almost always mean query folding broke early, forcing Excel to download the entire table and filter locally. Right-click each step and look for "View Native Query" — the last step where it is available is where folding stopped. Move your row filters and column removals before that point so they fold back to the server. Also avoid loading whole large tables when you only need a subset; add a WHERE-style filter or write a native query so the server returns just the rows you actually use in the report.

Power Query keeps asking for credentials on every refresh

Repeated credential prompts mean the saved connection credentials were not stored or have expired. Go to Data > Get Data > Data Source Settings, select the SQL Server entry, and click Edit Permissions to re-enter and save the credentials at the correct level (server or database). If your organisation uses a password that changes regularly, the stored database credentials will need updating after each change. For Windows authentication, ensure your domain account still has access, as a revoked permission also shows up as a repeated prompt.

Frequently Asked Questions

  • How do I connect Excel to a SQL Server database with Power Query?+
    Go to Data > Get Data > From Database > From SQL Server database. Enter the server name and, optionally, the database name. Choose an authentication method — Windows for your domain account, or Database for a SQL username and password from your DBA — and click Connect. In the Navigator, tick the tables or views you want, then click Transform Data to shape them or Load to place them on a worksheet. You need at least SELECT permission on the objects you are reading, and you must be on the network or VPN that can reach the server.
  • What is query folding and why does it matter?+
    Query folding is Power Query's ability to translate your steps into a single SQL statement that runs on the server rather than in Excel. When folding works, the database filters, removes columns, and aggregates before sending data back, so only the small final result travels over the network — making refreshes fast even on huge tables. Folding breaks when you add a step SQL cannot express, at which point Excel downloads everything and processes it locally. Keeping row filters and column removals early, while folding is still active, is the key to fast SQL queries.
  • Should I import a whole table or write my own SQL query?+
    For most work, load the table and add filters in Power Query, letting folding push those filters to the server — this keeps the query maintainable and still fast. Write your own native SQL query when you need precise control, a join across several tables, or logic that is easier to express in SQL than in the Power Query interface. Avoid importing an entire multi-million-row table with no filter, because it produces a slow, heavy workbook. The goal either way is to return only the rows and columns your report actually uses.
  • Does refreshing a Power Query connection change the database?+
    No. Power Query is strictly read-only when it pulls data — refreshing re-runs your SELECT-style query and updates the worksheet, but it never writes, updates, or deletes anything in SQL Server. This is why a read-only login is sufficient and recommended for reporting. Your edits inside Excel stay in the workbook and do not flow back to the database. If you need to send data back to SQL Server, that requires a separate tool or a purpose-built process, not a standard Power Query refresh.