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*fromopendatasource (' microsoft.ace.oledb.12.0 ', ' Data source= ' c:\book1.xlsx '; User id=admin; password=; Extended properties=excel 12.0 ') ... [sheet1$]Copy Code

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

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

Version 2003:

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

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

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

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;Copy Code

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;Copy Code

# Site Name: Excel Tips Web | Excel 2010/2007 New Territories # Attribution Author: Apolloh # copyright notice: Copyright non-author himself reproduced subject to permission and note the author and source # This article from: # Citation: # Applicable version: 2010 2007 2003 Previous version # locale: Simplified Chinese Text (in the top right corner of the page) # Content Introduction: # Article Address: http://www.exceltip.net/thread-5862-1-1-0.html # Learning Method: Mastering Excel Skills is the key to hands-on operation | download ≠ knowledge

Both 2007 and 2003 are available

Select*fromopendatasource (' microsoft.ace.oledb.12.0 ', ' Data source= ' D:\test1.xls '; User id=admin; password=; Extended properties= "Excel 12.0 Xml; Hdr=yes;imex=1 "; ') ... [sheet1$]Copy Code

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.