How SQL Server Imports Excel

Source: Internet
Author: User

--From the Excel file, import data into the SQL database, very simple, directly with the following statement:/*===================================================================*/- -If the table that accepts 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$)--If you import data and generate a table select * into table from OPENROWSET (' MICROSOFT. JET. oledb.4.0 ', ' Excel 5.0; Hdr=yes;database=c:\test.xls ', sheet1$)/*===================================================================*/- -If you export data from a SQL database to Excel, if the Excel file already exists and 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-if the Excel file does not exist, you can also use BCP to lead to a file of the class Excel, note the case:--export the table to exec master. xp_cmdshell ' bcp database name. dbo. Table name out "C:\Test.xls"///-/s "server name"/"User name"-P "password"--the case of the 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" user name "-P" password "'/*--Description: C:\Test.xls is an imported/exported Excel file name. sheet1$ The worksheet name for the Excel file, which is typically added in order to be used normally.--*/
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.