Sql server SSI将多行合并为一行

Sql server SSI将多行合并为一行,sql-server,ssis,Sql Server,Ssis,我有一个平面文件,它有6列:NoteID、Sequence、FileNumber、EntryDte、NoteType和NoteText。NoteText列有200个字符,如果注释长度超过200个字符,则文件中的第二行包含注释的续行。它看起来像这样: |NoteID | Sequence | NoteText | --------------------------------------------- |1234 | 1 | start

我有一个平面文件,它有6列:NoteID、Sequence、FileNumber、EntryDte、NoteType和NoteText。NoteText列有200个字符,如果注释长度超过200个字符,则文件中的第二行包含注释的续行。它看起来像这样:

|NoteID |  Sequence |   NoteText              |
 ---------------------------------------------
|1234   |    1      |   start of note text... |

|1234   |    2      |   continue of note....  |

|1234   |    3      |   more continuation of first note... |

|1235   |    1      |   start of new note.... |
| NoteID      |  Sequence |   NoteText              |
 ---------------------------------------------------
|1234         |    1      |   start of note text... continue of note... more continuation of first note... |

|1235         |    1      |   start of new note.... |
select distinct 
        noteid,
        min(sequence) over (partition by n.noteid order by n.sequence) as sequence,
        stuff((select ' ' + NoteText
                      from notes n1
                      where n.noteid = n1.noteid
                      for xml path ('')
                      ),1,1,'') as NoteText
from notes n;
如何在SSIS中将多行NoteText组合成一行,使该行符合以下要求:

|NoteID |  Sequence |   NoteText              |
 ---------------------------------------------
|1234   |    1      |   start of note text... |

|1234   |    2      |   continue of note....  |

|1234   |    3      |   more continuation of first note... |

|1235   |    1      |   start of new note.... |
| NoteID      |  Sequence |   NoteText              |
 ---------------------------------------------------
|1234         |    1      |   start of note text... continue of note... more continuation of first note... |

|1235         |    1      |   start of new note.... |
select distinct 
        noteid,
        min(sequence) over (partition by n.noteid order by n.sequence) as sequence,
        stuff((select ' ' + NoteText
                      from notes n1
                      where n.noteid = n1.noteid
                      for xml path ('')
                      ),1,1,'') as NoteText
from notes n;
非常感谢任何帮助

更新:将SynchronousInputID更改为None会暴露Output0Buffer,我可以使用它。下面是我现在所拥有的。
我现在的问题是,我必须将输出列从Wstr(4000)转换为NText,因为有些注释太长了。当它导入到我的SQL表中时,它只是jibberish字符,而不是实际的注释。

在SQL Server Management Studio(使用SQL)中,您可以使用
stuff
函数和
XML Path
轻松地将您的NoteText字段组合到一个列中,如下所示:

|NoteID |  Sequence |   NoteText              |
 ---------------------------------------------
|1234   |    1      |   start of note text... |

|1234   |    2      |   continue of note....  |

|1234   |    3      |   more continuation of first note... |

|1235   |    1      |   start of new note.... |
| NoteID      |  Sequence |   NoteText              |
 ---------------------------------------------------
|1234         |    1      |   start of note text... continue of note... more continuation of first note... |

|1235         |    1      |   start of new note.... |
select distinct 
        noteid,
        min(sequence) over (partition by n.noteid order by n.sequence) as sequence,
        stuff((select ' ' + NoteText
                      from notes n1
                      where n.noteid = n1.noteid
                      for xml path ('')
                      ),1,1,'') as NoteText
from notes n;
您可能希望研究在SSI中做类似事情的东西。查看此链接,了解如何在SSIS中创建脚本组件以执行类似操作:


有趣的问题。我很好奇第一张桌子是怎么来的。如果这是一个SQL Server表,我会将NoteText定义为nvarchar(max),以便在第二个表中得到结果。表2中的序列是多余的,除非涉及到遗留连接。我的源代码是一个平面文件,所以我不能使用您建议的SQL。您指向Concat行的链接看起来很有希望,但它们引用的Output0Buffer似乎没有向我公开。在我的ProcessInputRow函数Output0Buffer.AddRow()@cciservices中,这一行对我不起作用。你添加的代码对你有用吗?我并没有经常使用脚本组件,所以我对它了解不多。但这看起来应该接近您所需要的。不,它没有,因为脚本转换编辑器无法识别Output0Buffer。请检查这一点,看看是否有帮助:感谢您的帮助-请参阅上面我更新的问题。