尝试以下模式:
1.You are multicasting the dataset and grouping by just your lookup column
2.inserting your lookup and adding the scopeidentity(lookupid) to you grouped data
3.joining in the data you inserted to effective add your lookup value to every row
4.unioning your data back in
我不是很肯定,但是您可能需要添加一些类别才能使用合并联接。
,
SSIS数据流
Here is the final SSIS data flow model...
根据@KeithL的建议,我在合并加入之前添加了排序。
脚本组件
using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
public class ScriptMain : UserComponent
{
IDTSConnectionManager100 serverConMgr;
public override void PreExecute()
{
base.PreExecute();
serverConMgr = this.Connections.Connection;
}
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
using (SqlConnection serverCon = new SqlConnection(serverConMgr.ConnectionString))
{
SqlCommand sql = new SqlCommand(
"INSERT INTO DIM.CONTRIBUTOR (CONTRIBUTOR) VALUES ('" + Row.CONTRIBUTOR + "') " +
"\n SELECT CAST(SCOPE_IDENTITY() AS INT) AS 'ID'",serverCon);
serverCon.Open();
SqlDataReader data = sql.ExecuteReader();
while (data.Read())
{
Row.CONTRIBUTORID = data.GetInt32(0);
}
data.Close();
}
}
}
“脚本组件”是最棘手的部分。它插入新值并检索相应的ID。下面是该脚本的代码。
请注意3件重要的事情...
- 数据库连接管理器(在这种情况下,名称为“ Connection”,必须为ADO.Net连接)
- Row.CONTRIBUTOR_ID是我在脚本编辑器的“输入和输出”部分中手动配置为输出的行
- 除非在SQL命令中将SCOPE_IDENTITY显式转换为int,否则SqlDataReader的“ GetInt32()”方法不适用于SCOPE_IDENTITY。
以下是与脚本相关的其他说明...
- 您可以insert and return SCOPE_IDENTITY through OLE DB command,但是相当复杂
- 这是Microsoft文档对how to retrieve data using SqlDataReader的引用
本文链接:https://www.f2er.com/3151504.html