How to import SQL Server excel and SQL Server excel

Source: Internet
Author: User

How to import SQL Server excel and SQL Server excel

-- Importing data from an Excel file to a SQL database is simple. Use the following statement: /* ===================================================== =============================*/-- if the table to be imported already exists insert into Table select * from OPENROWSET ('Microsoft. JET. OLEDB.4.0 ', 'excel 5.0; HDR = YES; DATABASE = c: \ test.xls', sheet1 $) -- if data is imported and the select * into table from OPENROWSET ('Microsoft. JET. OLEDB.4.0 ', 'excel 5.0; HDR = YES; DATABASE = c: \ test.xls', sheet1 $) /* ===================================================== =============================*/-- if the SQL database, export data to Excel. If the Excel file already exists and the header has been created according to the data to be received, 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 import Excel-like files. Note the case sensitivity: -- export the table EXEC master .. xp_mongoshell 'bcp database name. dbo. table name out "c: \ test.xls"/c-/S "server name"/U "username"-P "password" '-- export query status 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 "'/* -- Note: c: \ test.xls is the Excel file name for import/export. sheet1 $ is the worksheet name of the Excel file. You must add $ to use it normally. --*/

How can I export the query results in SQL server 2008 to an Excel table?

After the query is complete, press CTRL + A in the result bar to select all the results, right-click and select "Save the result... and save it as "*. csv file, you can open it in excel. Or copy the results to an excel table by copying the results together with the title.

How does SQL server Import excel documents?

In SQL server 2000, there is an import and export tool that can be used to export various types of data.
You can also right-click any table on the Database Management Interface (Enterprise Manager), or choose import/export.
Versions later than 2005 support copying and pasting, which is no different from operating files in this tutorial.

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.