How SQL Server Imports Excel

Source: Internet
Author: User

--From the Excel file, import data into the SQL database, very easy, directly with the following statement:/*=================================================================== */--assumes that the table that accepts the data import already exists insert into table select * from OPENROWSET (' MICROSOFT. JET. oledb.4.0 ', ' Excel 5.0; Hdr=yes;database=c:\test.xls ', sheet1$)--assuming import data and generate table select * into table from OPENROWSET (' MICROSOFT. JET. oledb.4.0 ', ' Excel 5.0; Hdr=yes;database=c:\test.xls ', sheet1$)/*===================================================================*/- -Assuming that you are exporting data from a SQL database to Excel, assuming that the Excel file already exists and that you have created a header for the data you want to receive, you can simply use: INSERT INTO OPENROWSET (' MICROSOFT. JET. oledb.4.0 ', ' Excel 5.0; Hdr=yes;database=c:\test.xls ', sheet1$) SELECT * FROM table-assuming that the Excel file does not exist, you can also use BCP to lead to Excel-like files, note uppercase and lowercase:--case of export table exec Master.. xp_cmdshell ' bcp database name. dbo. Table name out "C:\Test.xls"/C-/s "server name"/u "username"-P "password" '--case of export query exec master. xp_cmdshell ' bcp ' select au_fname, au_lname from pubs. Authors ORDER BY au_lname "Queryout" C:\Test.xls "/C-/s" server name "/u" username "-P" password "'/*--Description: C:\Test.xls for import/export EX CEL file name. sheet1$ is the worksheet name for the Excel file, and you typically add$ ability to use normally.--*/ 

How SQL Server Imports Excel

Related Article

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.