Import data in an Excel table to an SQL Server database

Source: Internet
Author: User
Tags management studio sql server management sql server management studio
Welcome to the Windows community forum and interact with 3 million technical staff. In the query analyzer, select Lee for the database object to write the SQL statement directly: if data is imported to the existing table, SELECT * FROMOPENROWSET (MICROSOFT. JET. OLEDB.4.0, Excel5.0; HDRYES; DATABASEc:

Welcome to the Windows community forum and interact with 3 million technical staff> go to the query analyzer and select Lee to directly write SQL statements for the database object: If you want to import data to an existing table, SELECT * from openrowset ('Microsoft. JET. OLEDB.4.0 ', 'excel 5.0; HDR = YES; DATABASE = c:

Welcome to the Windows community forum and interact with 3 million technicians>

In the query analyzer, select Lee for the database object to write the SQL statement directly:

If you want to import data to an existing table, use

Insert into Table SELECT * from openrowset ('Microsoft. JET. OLEDB.4.0'

, 'Excel 5.0; HDR = YES; DATABASE = c: \ test.xls ', sheet1 $)

Format

If you import data and add a table, use

SELECT * INTO table from openrowset ('Microsoft. JET. OLEDB.4.0'

, 'Excel 5.0; HDR = YES; DATABASE = c: \ test.xls ', sheet1 $)

.

The preceding statement reads all columns in the sheet 1 worksheet in an EXCEL file. If you only want to export some columns, you can

Insert into table (a1, a2, a3) SELECT a1, a2, a3 from openrowset ('Microsoft. JET. OLEDB.4.0'

, 'Excel 5.0; HDR = YES; DATABASE = c: \ test.xls ', sheet1 $)

OPENROWSET ('Microsoft. JET. OLEDB.4.0'

, 'Excel 5.0; HDR = YES; DATABASE = c: \ test.xls ', sheet1 $) as a table. For example, I wrote a sentence like this:

Insert into eval_channel_employee (channel, employee_id)

Select case a. Channel WHEN 'diy 'then 1 WHEN 'rdc 'THEN 0 WHEN 'kcm' THEN 2 ELSE 3 END

, B. id FROM

OPENROWSET ('Microsoft. JET. OLEDB.4.0'

, 'Excel 5.0; HDR = YES; DATABASE = c: \ temp \ name.xls ', sheet1 $) AS a, pers_employee B

WHERE a. employee code = B. code

Simple Method:

SQL2008 can directly implement the import function in SQL2005.

The procedure is as follows:

Step 1: log on to SQL Server Management Studio,

Step 2: Right-click "manage" in "Object Resource Manager" and click "import data" in the displayed list"

Step 3: click "Next" in the "Import wizard" dialog box to go to the "Select data source" dialog box. In the "Data Source" list, select "Microsoft Excel ", select the corresponding Excel document, and click "Next" (Be sure to check "first line containing column name" in this dialog box ", therefore, the column title in the Excel document is the column item title in the database table)

Step 4: Specify the target database service and click "Next "... To "complete"

Step 5: Go to SQL Server Management Studio and enter the imported database table. You can find the imported Excel document data.

Try the following:

Open SQL Server Configuration Manager and enable SQL Server Agent (Instance name ). Change startup mode to "automatic"

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.