SQL advanced application-how to use SQL to query Excel table data

Source: Internet
Author: User
Tags how to use sql

CopyCode The Code is as follows: exec sp_configure 'show advanced options', 1
Reconfigure
Exec sp_configure 'ad hoc distributed queries ', 1
Reconfigure

Copy codeThe Code is as follows: Select * From OpenDataSource ('Microsoft. Jet. oledb.4.0 ',
'Data source = E: \ haierweb \ myweb \ doc \ abc.xls; extended properties = Excel 8.0 ')... sheet1 $

The first line is used as the header.
The rest of the rows are considered to be of a data type and cannot be converted. If there is text or number, multiple rows are displayed, and the rest are null.

Employee information F2
Null name
664754 Zhang San
664783 Li Si

Null should be the employee ID. The first two rows are headers.

In this form, you should enter one more '(single quotation marks) before the number to forcibly convert it to the text format. Enter multiple cells with the same content, enter the characters, and press Ctrl + enter to enter the same characters in the selected cells.

Solution:Copy codeThe Code is as follows: Select * From OpenDataSource ('Microsoft. Jet. oledb.4.0 ',
'Data source = E: \ haierweb \ myweb \ doc \ abc.xls; extended properties = "Excel 8.0; HDR = yes; IMEX = 1;" ')... sheet1 $

HDR = yes, that is, the first column is used as the header.
IMEX = 1, which means to read the table content in a hybrid manner.

Jet supports so many databases, even HTML tables.

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.