【问题标题】:SSIS- retaining null values as null in the csv output file using script taskSSIS-使用脚本任务在csv输出文件中将空值保留为空
【发布时间】:2016-08-08 14:17:12
【问题描述】:

我正在使用执行 sql 任务读取 sql 查询,然后使用脚本任务使用本网站以下帖子中提到的方法将查询结果写入 csv 文件-

SSIS:将记录集写入文件的脚本任务 (SSIS: Script task to write recordset to file)。 除此之外,我需要的是在查询结果为 NULL 的 csv 文件中填充“null”。如何使用脚本任务来实现这个????我还需要写什么额外的代码??

【问题讨论】:

    标签: csv ssis script-task


    【解决方案1】:

    有几种方法可以做到这一点,但答案在 foreeach 数据行循环中的 Persist() 中:

           foreach (System.Data.DataRow row in table.Rows)
            {
                // TODO: For string based fields, capture the max length
                IEnumerable<string> fields = (row.ItemArray).Select(field => field.ToString());
    
                file.WriteLine(string.Join(delimiter, fields));
            }
    

    您必须在 lambda 表达式中测试 db null。虽然我没有测试过,但这应该可以工作:

    IEnumerable<string> fields = (row.ItemArray).Select(field => ((field  == DBNull.Value) "NULL" : field.ToString()));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-09
      • 1970-01-01
      相关资源
      最近更新 更多