简体   繁体   中英

SSIS Export 1 table to multiple Excel sheets

I want to export a large table from SQL Server to excel using SSIS. I have a col called Num that I want all the same values into the same excel sheet eg all the 1s in 1 sheet etc. How to do this with SSIS? Do I write a SQL command text?

Num
--
1
1
2
2
2
3
4
4

在此处输入图像描述

Export data from SQL Server to Excel and Excel file via using SSIS package:

  1. Configure ADO.NET connection:

To create a “Source” connection, right click “Connection Managers” and select “New ADO.NET Connection”.

a. Server Name – is the hostname or IP address of the database server where SQL is installed.

b. Authentication – is an “authentication type” used to connect Server that is selected on “Server Name” drop-down box. It can be either SQL Authentication or Windows Authentication.

c. Database Name – is the name of the database which we are going to use for data extracting.

  1. Configure ADO.NET Source:

To populate data from SQL Server table, you must configure ADO.Net source component. Double-click on “Data flow task” to do that. The window “Configure Data flow task” will open. Alternatively, you can select “Data Flow” that is located next to “Control Flow”. As we already configured SQL connection, we will drag and drop ADO.NET Source to data flow window.

Then select “SQL Command”, it will open a multi-line text box where we can write the Ad-Hoc query to extract data from the database.

  1. Configure excel destination Once we configure ADO.NET source, we will configure Excel destination. In SSIS tool-box, drag and drop excel destination in the data-flow window and rename it as “Sales Excel File”.

a. Excel connection manager – used to connect the excel file.

b. Data access method. Excel worksheet is considered as a table or view. If you select “Table or View”, drop down box “Name of excel sheet” will be filled with all worksheets that are created in the excel workbook.

c. Name of excel sheet. By default, this drop-down box is disabled. It will be enabled automatically when we select “Table or View” as data access mode. We also can select appropriate excel worksheet.

Then, choose:

a. Excel File Path – the location of the excel file.

b. Excel version – can select excel version from drop down box.

In order to export data from SQL table to excel file, you must map the fields of SQL table and Excel file. To do that, drag blue arrow beneath the ADO.NET component and drop it on Excel Destination component.

Double click on “Excel destination” to map the fields. “Excel destination editor” will open. Select “Mappings” option from the left pane of the dialog box. In mapping, input columns will be the columns of SQL Query output and destination columns will be the columns of the excel file. It is suggested to keep the same name of SQL Query output and excel columns. This will make mapping much easier because we do not need to map fields manually. SSIS will map columns automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM