Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SSI将数字添加到列中的重复值以使其唯一_C#_Sql Server_Ssis - Fatal编程技术网

C# SSI将数字添加到列中的重复值以使其唯一

C# SSI将数字添加到列中的重复值以使其唯一,c#,sql-server,ssis,C#,Sql Server,Ssis,我的数据只有一列中有一些重复记录。我希望在通过脚本组件运行数据后对它们进行过滤,以获取所有重复值,并向它们添加增量数字,使它们唯一 可以使用聚合组件吗? 例如,我的数据可能如下所示: Column1和Column2用作主键,因此我需要Column2在其值方面更为独特。 在将数字附加到副本后,看起来是这样的(注意“C”没有数字): 我注意到C没有数字。我将把这个练习留给你做。提示使用cnt DECLARE @a TABLE (col2 varchar(20)); INSERT INTO @a

我的数据只有一列中有一些重复记录。我希望在通过脚本组件运行数据后对它们进行过滤,以获取所有重复值,并向它们添加增量数字,使它们唯一

可以使用聚合组件吗?
例如,我的数据可能如下所示:

Column1和Column2用作主键,因此我需要Column2在其值方面更为独特。 在将数字附加到副本后,看起来是这样的(注意“C”没有数字):

我注意到C没有数字。我将把这个练习留给你做。提示使用cnt

DECLARE @a TABLE (col2 varchar(20));
INSERT INTO @a VALUES ('a'), ('a') , ('a'), ('b'), ('c'), ('c');

select aa.*, aa.col2 + '.' + cast(rn as varchar)   
from ( select a.*
            , row_number() over (partition by col2 order by col2) as rn
            , count(*)     over (partition by col2) as cnt 
         from @a a 
     ) aa 
where aa.cnt > 1
order by aa.col2;

update aa 
set aa.col2 = aa.col2 + '.' + cast(rn as varchar)
from ( select a.*
            , row_number() over (partition by col2 order by col2) as rn
            , count(*)     over (partition by col2) as cnt 
         from @a a 
     ) aa 
where aa.cnt > 1; 

select * from @a a
order by a.col2; 

其中cnt>1。你就是那个人!但我如何更新这些值以使其与新的重复值相等?对此仍然感到困惑。尝试了几种方法,但似乎无法解决这个问题。我该如何使用更新来实现这一点?明白了,谢谢!
DECLARE @a TABLE (col2 varchar(20));
INSERT INTO @a VALUES ('a'), ('a') , ('a'), ('b'), ('c'), ('c');

select aa.*, aa.col2 + '.' + cast(rn as varchar)   
from ( select a.*
            , row_number() over (partition by col2 order by col2) as rn
            , count(*)     over (partition by col2) as cnt 
         from @a a 
     ) aa 
where aa.cnt > 1
order by aa.col2;

update aa 
set aa.col2 = aa.col2 + '.' + cast(rn as varchar)
from ( select a.*
            , row_number() over (partition by col2 order by col2) as rn
            , count(*)     over (partition by col2) as cnt 
         from @a a 
     ) aa 
where aa.cnt > 1; 

select * from @a a
order by a.col2;