sql - 如何通过分组和计数在 SSIS 中获得所需的输出?

标签 sql sql-server ssis ssis-2012 ssis-2008

我正在创建一个 SSIS 包,如果一个产品标签存在重复的产品代码,则需要通知用户。我们通过在共享位置发送给我们的 csv 平面文件检索产品。

在这个例子中,我为产品标签 Physio Ormix 和 Nixen 设置了 Productcode = 1a。

所以基本上 productcode = 1a 是重复的,因为它也被 productlabel=Nixen 使用。因此,通知用户使用了重复的 ProductCode 和 Productlabel。我尝试创建一个按 ProductCode 执行分组并对其进行计数的聚合。

In this link is the image of my dataflow

有人可以告诉我如何做到这一点吗?

In this link is the desired output

最佳答案

我认为您可以使用脚本组件和条件拆分来获取重复项,而无需所有这些逻辑:

  1. 在数据流任务中添加一个脚本组件
  2. 添加 DT_BOOL 类型的输出列(示例名称为 Flag)
  3. 在脚本组件中编写一个类似的脚本:

    using System.Collections.Generic;
    
    public class ScriptMain:  
        UserComponent  
    
    {  
    
        List<string> lstKey = new List<string>;
        List<string> lstKeylabel = new List<string>;
    
        public override void Input0_ProcessInputRow(InputBuffer0 Row)  
        {  
    
            if(!lstKey.Contains(Row.ProductCode){
    
                lstKey.Add(Row.ProductCode);
                lstKeylabel.Add(Row.ProductCode + ";" + Row.ProductLabel);
                Row.Flag = true;
    
            }else if(lstKeylabel.Contains(Row.ProductCode + ";" + Row.ProductLabel)) {
    
                Row.Flag = true;
    
            }else{
    
                Row.Flag = false;
    
            }
    
        }  
    
    }
    
  4. 在具有类似表达式的脚本组件后添加条件拆分:

    [Flag] == true
    
  5. 所有通过真实路径的记录都是唯一的,所有通过错误路径的记录都是重复的。

关于sql - 如何通过分组和计数在 SSIS 中获得所需的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55036780/

相关文章:

sql - 授予对所有服务代理对象的权限

sql-server - 如何开始使用 SQL Server SSIS?

php - 阻止 php 中重复的用户名

java - 如何在Activiti 5.14中显示SQL查询?

sql - 将 name 存储为 "sysname"而不是 "nvarchar(128)"有什么好处?

sql - 我怎么能有像 SELECT id, (id in(2,3,4) ) as idIs234 来自 Messageset

sql - Azure 使用 SSIS 将数据从 1 db 复制到另一个 db

sql-server - 在 SQL Server 2005 中存储 SSIS 包需要什么权限?

sql - 将周工资信息分为日工资信息

PHP - 页面刷新时重新加载新记录