在 SQL Server 2005 中使用 SSIS 从平面文件导入时如何保留 NULL 值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4620755/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 08:47:37  来源:igfitidea点击:

How do I retain NULL values when using SSIS to import from flat file in SQL Server 2005

sqlsql-server-2005ssisnull

提问by ofm

I've exported records to a flat file delimited by "|" and it seems that when I import those records into a new database , SQL Server treats the NULL values as empty fields. IMy queries worked properly when the records/fields were NULL and so I want to either find a way to retain the NULL values in the data or convert the blank fields to NULL values. I'm assuming the former would be easier, but I don't know how to do that. Any help would be appreciated.

我已将记录导出到以“|”分隔的平面文件 似乎当我将这些记录导入新数据库时,SQL Server 将 NULL 值视为空字段。当记录/字段为 NULL 时,IMy 查询工作正常,因此我想找到一种方法来保留数据中的 NULL 值或将空白字段转换为 NULL 值。我假设前者会更容易,但我不知道该怎么做。任何帮助,将不胜感激。

回答by ScubaManDan

I just had the same problem. I resolved it by Changing the RetainNulls property in the properties of the Flat File Source in the Data Flow Task.

我只是遇到了同样的问题。我通过更改数据流任务中平面文件源属性中的 RetainNulls 属性来解决它。

回答by HLGEM

In your destination connection in the dataflow, there is a property that you can chceck that says Keep nulls, JUst check that. Why that isn't the default I'll never know.

在数据流中的目标连接中,您可以检查一个属性,该属性表示保留空值,只需检查即可。为什么这不是我永远不会知道的默认值。

Hmmm something stange going on there. I can suggest that you then clean the data and change it to null, you can either do this as part of the dataflow or do two dataflows, one which inserts the data into a staging table, then run an exectue SQl task to do the clean up and then create a dataflow to run fromthe staging table to the real table.

嗯,那里发生了一些奇怪的事情。我可以建议您然后清理数据并将其更改为空,您可以将其作为数据流的一部分来执行,也可以执行两个数据流,一个将数据插入到临时表中,然后运行执行 SQl 任务来进行清理up 然后创建一个数据流从临时表运行到真实表。

回答by Sam

in case anyone is looking how to do this when building the package programatically you need to set the variable in your CManagedComponentWrapper object

如果有人在以编程方式构建包时正在寻找如何执行此操作,您需要在 CManagedComponentWrapper 对象中设置变量

CManagedComponentWrapper instanceSource = ComponentSource
...
instanceSource.SetComponentProperty("RetainNulls", true);