How to selectively import an XLS into an SQL Serve

2019-08-22 06:21发布

I have an XLS file. Let's assume that it has 1000 rows in all, with 10 columns. I would like to import rows 5 through 995 (say), and columns 1 though 7 and 10. How can I do this using an SQL query, either though OPENROWSET or BULK INSERT? I am using SQL Server 2008.

3条回答
一纸荒年 Trace。
2楼-- · 2019-08-22 06:50
SELECT *
FROM OPENROWSET(
    'Microsoft.ACE.OLEDB.12.0',
    'Excel 12.0;HDR=No;Database=c:\path\to\file.xls',
    'SELECT * FROM [Sheet1$A5:J995]'
);
查看更多
走好不送
3楼-- · 2019-08-22 07:07

I would approach this in a slightly different way.

I would import all the data into the database, into a temporary table. Then I would query that table, extracting the information that's needed.

Alternatively, you could look at a SSIS process to do this.

查看更多
4楼-- · 2019-08-22 07:10

I had another idea.

You could also use a Linked Server which connects to the Excel document.
(This is probably an easier approach for you.)

See: http://support.microsoft.com/kb/306397

查看更多
登录 后发表回答