How do I query Excel data with SQL statements?

Source: Internet
Author: User

How do I query Excel data with SQL statements?

Q: How do I query Excel data with SQL statements?
A: The following statements can query data in an Excel worksheet in SQL Server.

Versions 2007 and 2010:

SELECT *
From OpenDataSource (' microsoft.ace.oledb.12.0 ',
' Data source= ' c:\book1.xlsx '; User id=admin; password=; Extended properties=excel 12.0 ') ... [sheet1$]

SELECT * from OPENROWSET (' microsoft.ace.oledb.12.0 ', ' Excel 12.0;database=c:\book1.xlsx ', ' SELECT * from [sheet1$a1:d 100] ')

SELECT * from OPENROWSET (' microsoft.ace.oledb.12.0 ', ' Excel 12.0;database=c:\book1.xlsx ', ' SELECT * from [sheet1$] ')

Version 2003:

SELECT *
From OpenDataSource (' microsoft.jet.oledb.4.0 ',
' Data source= ' C:\Book1.xls '; User id=admin; password=; Extended properties=excel 8.0 ') ... [sheet1$]

SELECT * from OPENROWSET (' microsoft.jet.oledb.4.0 ', ' Excel 8.0;database=c:\book1.xls ', ' SELECT * from [sheet1$] ')

SELECT * from OPENROWSET (' microsoft.jet.oledb.4.0 ', ' Excel 8.0;database=c:\book1.xls ', ' select * from [sheet1$a1:d100] ' )

Also, you need to use the login account with the server sysadmin role permission to open the SQL Server ' Ad Hoc distributed Queries ' switch by first executing the following statement.

exec sp_configure ' show advanced options ', 1;reconfigure;
exec sp_configure ' Ad Hoc distributed Queries ', 1;reconfigure;

After executing the query, turn off the ' Ad Hoc distributed Queries ' switch with the reverse order of the statements.

exec sp_configure ' Ad Hoc distributed Queries ', 0;
Reconfigure;exec sp_configure ' show advanced options ', 0;reconfigure;

# Site Name: Excel Tips Web | Excel 2010/2007 New Territories
# Attribution Author: Apolloh
# Copyright Disclaimer: All rights reserved by the author and the author and source
# This article comes from:
# Citation works:
# Applicable version: 2010 2007 2003 Previous version
# Locale: Simplified Chinese (the top right corner of the page is simple and easy to transform)
# Content Introduction:
# Article Address: http://www.exceltip.net/thread-5862-1-1-0.html
# How to learn: The key to mastering Excel skills is hands-on | download ≠ knowledge

Both 2007 and 2003 are available

How do I query Excel data with SQL statements?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.