Skip to content

Commit de0ee7b

Browse files
Merge pull request #33671 from PhilB-MSFT/patch-13
Update import-data-from-excel-to-sql.md
2 parents a7e726c + a6b93c0 commit de0ee7b

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

docs/relational-databases/import-export/import-data-from-excel-to-sql.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Import Data from Excel to SQL Server or Azure SQL Database
33
description: This article describes methods to import data from Excel to SQL Server or Azure SQL Database. Some use a single step, others require an intermediate text file.
44
author: rwestMSFT
55
ms.author: randolphwest
6-
ms.date: 05/19/2025
6+
ms.date: 07/16/2025
77
ms.service: sql
88
ms.subservice: data-movement
99
ms.topic: concept-article
@@ -74,7 +74,7 @@ To start learning how to build SSIS packages, see the tutorial [How to Create an
7474
> [!IMPORTANT]
7575
> In [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)], you can't import directly from Excel. You must first [export the data to a text (CSV) file](import-bulk-data-by-using-bulk-insert-or-openrowset-bulk-sql-server.md).
7676
77-
The following examples use the JET provider, because the ACE provider included with Office that connects to Excel data sources is intended for interactive client-side use.
77+
The following examples use the JET provider. The ACE provider included with Office that connects to Excel data sources is intended for interactive client-side use, which can cause unexpected results when used non-interactively.
7878

7979
### Distributed queries
8080

@@ -100,6 +100,7 @@ The following code sample uses `OPENROWSET` to import the data from the Excel `S
100100
```sql
101101
USE ImportFromExcel;
102102
GO
103+
103104
SELECT * INTO Data_dq
104105
FROM OPENROWSET('Microsoft.JET.OLEDB.4.0',
105106
'Excel 8.0; Database=C:\Temp\Data.xls', [Sheet1$]);
@@ -111,6 +112,7 @@ Here's the same example with `OPENDATASOURCE`.
111112
```sql
112113
USE ImportFromExcel;
113114
GO
115+
114116
SELECT * INTO Data_dq
115117
FROM OPENDATASOURCE('Microsoft.JET.OLEDB.4.0',
116118
'Data Source=C:\Temp\Data.xls;Extended Properties=Excel 8.0')...[Sheet1$];
@@ -136,21 +138,22 @@ You can also configure a persistent connection from [!INCLUDE [ssnoversion-md](.
136138
```sql
137139
USE ImportFromExcel;
138140
GO
141+
139142
SELECT * INTO Data_ls FROM EXCELLINK...[Data$];
140143
GO
141144
```
142145

143146
You can create a linked server from SQL Server Management Studio (SSMS), or by running the system stored procedure `sp_addlinkedserver`, as shown in the following example.
144147

145148
```sql
146-
DECLARE @RC INT;
147-
DECLARE @server NVARCHAR(128);
148-
DECLARE @srvproduct NVARCHAR(128);
149-
DECLARE @provider NVARCHAR(128);
150-
DECLARE @datasrc NVARCHAR(4000);
151-
DECLARE @location NVARCHAR(4000);
152-
DECLARE @provstr NVARCHAR(4000);
153-
DECLARE @catalog NVARCHAR(128);
149+
DECLARE @RC AS INT;
150+
DECLARE @server AS NVARCHAR (128);
151+
DECLARE @srvproduct AS NVARCHAR (128);
152+
DECLARE @provider AS NVARCHAR (128);
153+
DECLARE @datasrc AS NVARCHAR (4000);
154+
DECLARE @location AS NVARCHAR (4000);
155+
DECLARE @provstr AS NVARCHAR (4000);
156+
DECLARE @catalog AS NVARCHAR (128);
154157

155158
-- Set parameter values
156159
SET @server = 'EXCELLINK';
@@ -159,7 +162,9 @@ SET @provider = 'Microsoft.JET.OLEDB.4.0';
159162
SET @datasrc = 'C:\Temp\Data.xls';
160163
SET @provstr = 'Excel 8.0';
161164

162-
EXEC @RC = [master].[dbo].[sp_addlinkedserver] @server,
165+
EXECUTE
166+
@RC = [master].[dbo].[sp_addlinkedserver]
167+
@server,
163168
@srvproduct,
164169
@provider,
165170
@datasrc,
@@ -207,11 +212,9 @@ As described previously in the [Prerequisites](#prerequisites) section, you have
207212
```sql
208213
USE ImportFromExcel;
209214
GO
215+
210216
BULK INSERT Data_bi FROM 'C:\Temp\data.csv'
211-
WITH (
212-
FIELDTERMINATOR = ',',
213-
ROWTERMINATOR = '\n'
214-
);
217+
WITH (FIELDTERMINATOR = ',', ROWTERMINATOR = '\n');
215218
GO
216219
```
217220

0 commit comments

Comments
 (0)