【问题标题】:Replacing " " with comma (,) in SSIS在 SSIS 中用逗号 (,) 替换“”
【发布时间】:2015-04-28 05:19:28
【问题描述】:

我正在尝试导入一个文本文件,其中制表符分隔且文本限定符是双引号。 我正在遵循指南: http://www.ideaexcursion.com/2008/11/12/handling-embedded-text-qualifiers/

我想要以下文字

"655295" "Keisuke" "" "Ueda" "1-2-2, Central Park East F201" "Utase, Mihama-Ku"

转换成

"655295","Keisuke","","Ueda","1-2-2, Central Park East F201","Utase, Mihama-Ku"

我尝试了派生列转换,但没有帮助。我尝试了脚本组件,但这也不起作用。有人可以在这里帮助我吗?

提前谢谢你!!

【问题讨论】:

    标签: ssis double quotes derived


    【解决方案1】:

    我在脚本组件中使用了以下代码:

    public override void Input0_ProcessInputRow(Input0Buffer Row)
        {
            /*
             * Add your code here
             */
            String inputString = Row.line.ToString();
    
            int count = Row.line.Split('"').Length - 1;
            int counter = 1;
    
            while (counter < count)
            {
                if (counter % 2 == 0)
                {
                    int StartIndex = GetNthIndex(inputString.ToString(), Convert.ToChar("\""), counter);
                    int EndIndex = GetNthIndex(inputString.ToString(), Convert.ToChar("\""), counter + 1);
    
                    inputString = inputString.ToString().Substring(0, StartIndex + 1) + "," +
                    inputString.ToString().Substring(EndIndex);
    
                }
                else
                {
                }
                counter = counter + 1;
            }
            Row.OutputLine = inputString;
        }
        int GetNthIndex(string s, char t, int n)
        {
            int count = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == t)
                {
                    count++;
                    if (count == n)
                    {
                        return i;
                    }
                }
            }
            return -1;
        }
    

    【讨论】:

      【解决方案2】:

      获取一个变量并将字符串存储在变量中。

      然后使用派生列使用字符串函数作为

      REPLACE(@user:Variable1,"\" \"","\",\"")
      

      这将适用于您的问题...

      【讨论】:

        【解决方案3】:

        您可以通过以下步骤实现它:-

        1) 在平面文件连接管理器中,请执行以下操作以将其配置为每行仅获取一列 - 一世。不要放任何“文本限定符” ii.行分隔符 = {CR}{LF} iii.修改 Column delimited = {CR} 并刷新元数据,这样您将只看到一列。请给它一个具体的名字,我现在将它称为“Col”。

        2) 添加派生列转换并将表达式设为 "(DT_STR,100,1252)REPLACE(Col,"\" \"","\",\"")"。您将在新列中获得以下所需的输出 -

        "655295","Keisuke","","Ueda","1-2-2, Central Park East F201","Utase, Mihama-Ku"
        

        您可以将此输出放在不同的平面文件中,然后使用不同的 DFT 或包将该文件导入表中,或者您可以添加脚本组件将其拆分为不同的列,以便您可以使用相同的 DFT 将数据导入表中。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-05-29
          • 1970-01-01
          • 2013-08-05
          相关资源
          最近更新 更多