Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.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
Ssis 在SSI中将单个记录拆分为多个记录_Ssis - Fatal编程技术网

Ssis 在SSI中将单个记录拆分为多个记录

Ssis 在SSI中将单个记录拆分为多个记录,ssis,Ssis,我想知道如何在SSI中将单个字段拆分为多行/行 我有一个名为Comments的字段,最多可以容纳1240个字符。每行最多只能容纳60个字符。我需要这些行具有SA-ST的记录ID,这取决于注释的长度。 当前记录: Comments In the name of Robert of the House Baratheon, the First of his Name, King of the Andals and the Rhoynar and the First Men, Lord of the

我想知道如何在SSI中将单个字段拆分为多行/行

我有一个名为Comments的字段,最多可以容纳1240个字符。每行最多只能容纳60个字符。我需要这些行具有SA-ST的记录ID,这取决于注释的长度。 当前记录:

Comments
In the name of Robert of the House Baratheon, the First of his Name, King of the Andals and the Rhoynar and the First Men, Lord of the Seven Kingdoms and Protector of the Realm, by the word of Eddard of the House Stark, Lord of Winterfell and Warden of the North, I do sentence you to die.
我希望SSI的输出如下所示:

SA In the name of Robert of the House Baratheon, the First of 
SB his Name, King of the Andals and the Rhoynar and the First 
SC Men, Lord of the Seven Kingdoms and Protector of the Realm,
SD  by the word of Eddard of the House Stark, Lord of Winterfe
SE  ll and Warden of the North, I do sentence you to die.
我简要介绍了我认为您正在寻找的内容(可以很容易地更改为特定于SSIS的内容)。第
SE
行中有一个细微的差别,在ll前面有一个前导空格,而我没有,但我认为这是你对问题的框架造成的

测试仪溶液

// Tester solution for https://stackoverflow.com/q/65126044/181965
using System;
using System.Collections;
using System.Collections.Generic;
                    
public static class Extensions
{
    // https://stackoverflow.com/questions/3008718/split-string-into-smaller-strings-by-length-variable
    public static IEnumerable<string> SplitByLength(this string str, int maxLength) 
    {
        for (int index = 0; index < str.Length; index += maxLength) 
        {
            yield return str.Substring(index, Math.Min(maxLength, str.Length - index));
        }
    }   
}   
public class Program
{
    public static void Main()
    {
        // Simulate Row value
        string comments = "In the name of Robert of the House Baratheon, the First of his Name, King of the Andals and the Rhoynar and the First Men, Lord of the Seven Kingdoms and Protector of the Realm, by the word of Eddard of the House Stark, Lord of Winterfell and Warden of the North, I do sentence you to die.";
        
        // Given the above, the expectation is that we will break the string into 60 character length strings with S A-T preceding the line. Expected output
/*
SA In the name of Robert of the House Baratheon, the First of 
SB his Name, King of the Andals and the Rhoynar and the First 
SC Men, Lord of the Seven Kingdoms and Protector of the Realm,
SD  by the word of Eddard of the House Stark, Lord of Winterfe
SE  ll and Warden of the North, I do sentence you to die.
*/
        
        // Define our line length
        int lineLength = 59;
        
        // 65 is A in ASCII
        int commentEnumerator = 65;
        
        // Split comments into lineLength segments
        foreach (string line in comments.SplitByLength(lineLength))
        {
            // https://stackoverflow.com/questions/289792/int-to-char-in-c-sharp
            Console.WriteLine(string.Format("S{0} {1}", (char)commentEnumerator, line));
            commentEnumerator++;
        }
/*
SA In the name of Robert of the House Baratheon, the First of h
SB is Name, King of the Andals and the Rhoynar and the First Me
SC n, Lord of the Seven Kingdoms and Protector of the Realm, by
SD  the word of Eddard of the House Stark, Lord of Winterfell a
SE nd Warden of the North, I do sentence you to die.
*/
    }
    
}
脚本组件 这将充当转换(默认)

在“输入列”选项卡上,选中“注释”和“只读”即可

在输入和输出选项卡上,选择输出0并展开它。我们需要将属性
SynchronousID
从默认的
脚本组件。Inputs[Input 0]
更改为None

离开此选项卡之前,需要指定将保存输出数据的列。我假设我们正在创建两列-
RowId
Comment
,我将分别定义为长度为2和159的字符串。单击“添加列”两次,然后修改名称、数据类型和长度属性

未来的读者,为了获得额外的积分,您可以定义一个Int32类型的SSIS变量,并用lineLength填充它,然后将其添加到脚本选项卡上的只读变量中,以获得半灵活的解决方案

单击编辑脚本

using System;
using System.Collections.Generic;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;

public static class Extensions
{
    // https://stackoverflow.com/questions/3008718/split-string-into-smaller-strings-by-length-variable
    public static IEnumerable<string> SplitByLength(this string str, int maxLength)
    {
        for (int index = 0; index < str.Length; index += maxLength)
        {
            yield return str.Substring(index, Math.Min(maxLength, str.Length - index));
        }
    }
}

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
    int lineLength;

    public override void PreExecute()
    {
        base.PreExecute();
        // This is where I would access the SSIS variable if I went that route
        lineLength = 59;
    }

    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        // 65 is A in ASCII
        int commentEnumerator = 65;
        foreach (string line in Row.Comments.SplitByLength(lineLength))
        {
            // https://stackoverflow.com/questions/289792/int-to-char-in-c-sharp
            Output0Buffer.AddRow();
            Output0Buffer.RowId = "S" + (char)commentEnumerator;
            Output0Buffer.Comment = line;
            commentEnumerator++;
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用系统数据;
使用Microsoft.SqlServer.Dts.Pipeline.Wrapper;
使用Microsoft.SqlServer.Dts.Runtime.Wrapper;
公共静态类扩展
{
// https://stackoverflow.com/questions/3008718/split-string-into-smaller-strings-by-length-variable
公共静态IEnumerable SplitByLength(此字符串str,int maxLength)
{
对于(int index=0;index
这就是这次行动的结果

我简要介绍了我认为您正在寻找的内容(可以很容易地更改为特定于SSI的内容)。第
SE
行中有一个细微的差别,在ll前面有一个前导空格,而我没有,但我认为这是你对问题的框架造成的

测试仪溶液

// Tester solution for https://stackoverflow.com/q/65126044/181965
using System;
using System.Collections;
using System.Collections.Generic;
                    
public static class Extensions
{
    // https://stackoverflow.com/questions/3008718/split-string-into-smaller-strings-by-length-variable
    public static IEnumerable<string> SplitByLength(this string str, int maxLength) 
    {
        for (int index = 0; index < str.Length; index += maxLength) 
        {
            yield return str.Substring(index, Math.Min(maxLength, str.Length - index));
        }
    }   
}   
public class Program
{
    public static void Main()
    {
        // Simulate Row value
        string comments = "In the name of Robert of the House Baratheon, the First of his Name, King of the Andals and the Rhoynar and the First Men, Lord of the Seven Kingdoms and Protector of the Realm, by the word of Eddard of the House Stark, Lord of Winterfell and Warden of the North, I do sentence you to die.";
        
        // Given the above, the expectation is that we will break the string into 60 character length strings with S A-T preceding the line. Expected output
/*
SA In the name of Robert of the House Baratheon, the First of 
SB his Name, King of the Andals and the Rhoynar and the First 
SC Men, Lord of the Seven Kingdoms and Protector of the Realm,
SD  by the word of Eddard of the House Stark, Lord of Winterfe
SE  ll and Warden of the North, I do sentence you to die.
*/
        
        // Define our line length
        int lineLength = 59;
        
        // 65 is A in ASCII
        int commentEnumerator = 65;
        
        // Split comments into lineLength segments
        foreach (string line in comments.SplitByLength(lineLength))
        {
            // https://stackoverflow.com/questions/289792/int-to-char-in-c-sharp
            Console.WriteLine(string.Format("S{0} {1}", (char)commentEnumerator, line));
            commentEnumerator++;
        }
/*
SA In the name of Robert of the House Baratheon, the First of h
SB is Name, King of the Andals and the Rhoynar and the First Me
SC n, Lord of the Seven Kingdoms and Protector of the Realm, by
SD  the word of Eddard of the House Stark, Lord of Winterfell a
SE nd Warden of the North, I do sentence you to die.
*/
    }
    
}
脚本组件 这将充当转换(默认)

在“输入列”选项卡上,选中“注释”和“只读”即可

在输入和输出选项卡上,选择输出0并展开它。我们需要将属性
SynchronousID
从默认的
脚本组件。Inputs[Input 0]
更改为None

离开此选项卡之前,需要指定将保存输出数据的列。我假设我们正在创建两列-
RowId
Comment
,我将分别定义为长度为2和159的字符串。单击“添加列”两次,然后修改名称、数据类型和长度属性

未来的读者,为了获得额外的积分,您可以定义一个Int32类型的SSIS变量,并用lineLength填充它,然后将其添加到脚本选项卡上的只读变量中,以获得半灵活的解决方案

单击编辑脚本

using System;
using System.Collections.Generic;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;

public static class Extensions
{
    // https://stackoverflow.com/questions/3008718/split-string-into-smaller-strings-by-length-variable
    public static IEnumerable<string> SplitByLength(this string str, int maxLength)
    {
        for (int index = 0; index < str.Length; index += maxLength)
        {
            yield return str.Substring(index, Math.Min(maxLength, str.Length - index));
        }
    }
}

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
    int lineLength;

    public override void PreExecute()
    {
        base.PreExecute();
        // This is where I would access the SSIS variable if I went that route
        lineLength = 59;
    }

    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        // 65 is A in ASCII
        int commentEnumerator = 65;
        foreach (string line in Row.Comments.SplitByLength(lineLength))
        {
            // https://stackoverflow.com/questions/289792/int-to-char-in-c-sharp
            Output0Buffer.AddRow();
            Output0Buffer.RowId = "S" + (char)commentEnumerator;
            Output0Buffer.Comment = line;
            commentEnumerator++;
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用系统数据;
使用Microsoft.SqlServer.Dts.Pipeline.Wrapper;
使用Microsoft.SqlServer.Dts.Runtime.Wrapper;
公共静态类扩展
{
// https://stackoverflow.com/questions/3008718/split-string-into-smaller-strings-by-length-variable
公共静态IEnumerable SplitByLength(此字符串str,int maxLength)
{
对于(int index=0;index
这就是这次行动的结果


是否还有其他数据(第X章,字符Y)与之一起使用,或者注释是唯一的入站数据?如果有其他数据,会发生什么,我们会重复吗?(瓦利斯,南非)。。。