简体   繁体   English

SSIS 将 1 个表导出到多个 Excel 表

[英]SSIS Export 1 table to multiple Excel sheets

I want to export a large table from SQL Server to excel using SSIS.我想使用 SSIS 将一个大表从 SQL 服务器导出到 excel。 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?我有一个名为 Num 的列,我希望将所有相同的值放入同一张 excel 表中,例如一张表中的所有 1 等。如何使用 SSIS 执行此操作? Do I write a SQL command text?我要写 SQL 命令文本吗?

Num
--
1
1
2
2
2
3
4
4

在此处输入图像描述

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

  1. Configure ADO.NET connection:配置ADO.NET连接:

To create a “Source” connection, right click “Connection Managers” and select “New ADO.NET Connection”.要创建“源”连接,请右键单击“连接管理器”和 select“新 ADO.NET 连接”。

a.一个。 Server Name – is the hostname or IP address of the database server where SQL is installed.服务器名称– 是安装 SQL 的数据库服务器的主机名或 IP 地址。

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.它可以是 SQL 身份验证或 Windows 身份验证。

c. c。 Database Name – is the name of the database which we are going to use for data extracting. Database Name - 是我们将用于数据提取的数据库的名称。

  1. Configure ADO.NET Source:配置ADO.NET 源码:

To populate data from SQL Server table, you must configure ADO.Net source component.要从 SQL 服务器表填充数据,您必须配置 ADO.Net 源组件。 Double-click on “Data flow task” to do that.双击“数据流任务”即可。 The window “Configure Data flow task” will open. window“配置数据流任务”将打开。 Alternatively, you can select “Data Flow” that is located next to “Control Flow”.或者,您可以 select 位于“控制流”旁边的“数据流”。 As we already configured SQL connection, we will drag and drop ADO.NET Source to data flow window.由于我们已经配置了 SQL 连接,我们将把 ADO.NET 源拖放到数据流 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.然后 select “SQL 命令”,它将打开一个多行文本框,我们可以在其中编写 Ad-Hoc 查询以从数据库中提取数据。

  1. Configure excel destination Once we configure ADO.NET source, we will configure Excel destination.配置 excel 目标 一旦我们配置 ADO.NET 源,我们将配置 Excel 目标。 In SSIS tool-box, drag and drop excel destination in the data-flow window and rename it as “Sales Excel File”.在 SSIS 工具箱中,将 excel 目标拖放到数据流 window 中,并将其重命名为“Sales ZC1D81AF589ZEDDED949”。

a.一个。 Excel connection manager – used to connect the excel file. Excel 连接管理器——用于连接 excel 文件。

b.湾。 Data access method.数据访问方法。 Excel worksheet is considered as a table or view. Excel 工作表被视为表格或视图。 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.如果您 select “表或视图”,下拉框“excel 表的名称”将填充在 excel 工作簿中创建的所有工作表。

c. c。 Name of excel sheet. excel板材的名称。 By default, this drop-down box is disabled.默认情况下,此下拉框处于禁用状态。 It will be enabled automatically when we select “Table or View” as data access mode.当我们将 select “表或视图”作为数据访问模式时,它将自动启用。 We also can select appropriate excel worksheet.我们也可以 select 适当的 excel 工作表。

Then, choose:然后,选择:

a.一个。 Excel File Path – the location of the excel file. Excel 文件路径 - excel 文件的位置。

b.湾。 Excel version – can select excel version from drop down box. Excel 版本 - 可以 select excel 版本从下拉框中。

In order to export data from SQL table to excel file, you must map the fields of SQL table and Excel file. 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.为此,将ADO.NET component下方的蓝色箭头拖到Excel Destination组件上。

Double click on “Excel destination” to map the fields.双击“Excel 目的地”到 map 字段。 “Excel destination editor” will open. “Excel 目标编辑器”将打开。 Select “Mappings” option from the left pane of the dialog box. Select 对话框左窗格中的“映射”选项。 In mapping, input columns will be the columns of SQL Query output and destination columns will be the columns of the excel file.在映射中,输入列将是 SQL 查询 output 的列,目标列将是 excel 文件的列。 It is suggested to keep the same name of SQL Query output and excel columns.建议保留 SQL 的同名查询 output 和 excel 列。 This will make mapping much easier because we do not need to map fields manually.这将使映射更容易,因为我们不需要手动 map 字段。 SSIS will map columns automatically. SSIS 将自动生成 map 列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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