0

我在尝试重复StackOverflow 文章的成功以将 CSV 文件中的 NULL 值传输到允许 NULL 的表列时遇到问题。

鉴于此 CSV 文件的文本分隔符 = 双引号和列分隔符 = 逗号。请注意,有两条记录以及从末尾算起的第 3 列和第 4 列,分别是“CELL_TXT”和“CELL_VAL”。第一列“CELL_TXT”包含一个文本值。如果此文本值可以计算为数字,则 CELL_VAL 将包含此数字值,否则为 NULL。

"FLDR","FILE_NM","TAB_IDX","TAB_NM","TAB_PART","LABEL_DESGTR","LABEL_TXT","SECT_NM","SEG_NM","COLMN_TXT","ROW_IDX","COLMN_IDX","COLMN_LETTR","CELL_TXT","CELL_VAL","LAST_OPER_ID","LAST_TIMESTMP"
"C:\corp_mlr_rebates\Processing\HHS\CGLIC","MLR_Template_CGLIC_Grand_Total.xls","1","Pt 1 and 2","Part 1","1.","Premium","Health Insurance Coverage","Individual","Total as of 12/31/11","19","6","F","2",2,"HHSSWEEP","1/15/2013 1:40:20 PM"
"C:\corp_mlr_rebates\Processing\HHS\CGLIC","MLR_Template_CGLIC_Grand_Total.xls","1","Pt 1 and 2","Part 1","1.","Premium","Health Insurance Coverage","Individual","3/31/12","19","7","G","",,"HHSSWEEP","1/15/2013 1:40:20 PM"

请注意,对于第二行,CELL_TEXT 为空白“”,因此 CELL_VAL 在 CSV 文件中存储为 NULL,由紧跟在前一个列分隔符之后的连续逗号列分隔符指示。

我正在尝试将此文件导入到允许 CELL_VAL 表中为 NULL 的表中。这是完整的表格,尽管我们对 CELL_TXT 尤其是 CELL_VAL 列感兴趣。

CREATE TABLE [dbo].[HHS_GRD_STG](
    [FLDR] [varchar](255) NOT NULL,
    [FILE_NM] [varchar](80) NOT NULL,
    [TAB_IDX] [int] NOT NULL,
    [TAB_NM] [varchar](80) NOT NULL,
    [TAB_PART] [varchar](80) NOT NULL,
    [LABEL_DESGTR] [varchar](80) NOT NULL,
    [LABEL_TXT] [varchar](255) NOT NULL,
    [SECT_NM] [varchar](80) NOT NULL,
    [SEG_NM] [varchar](80) NOT NULL,
    [COLMN_TXT] [varchar](80) NOT NULL,
    [ROW_IDX] [int] NOT NULL,
    [COLMN_IDX] [int] NOT NULL,
    [COLMN_LETTR] [char](2) NOT NULL,
    [CELL_TXT] [varchar](255) NOT NULL,
    [CELL_VAL] [decimal](14, 4) NULL,
    [LAST_OPER_ID] [char](8) NOT NULL,
    [LAST_TIMESTMP] [datetime] NOT NULL
) ON [PRIMARY]

在 SSIS 中,我将输入文件对象定义为逗号分隔文件,其中包含 " 文本限定符和 {CR}{LF} 作为行分隔符。

在数据流任务中,我在文件源对象中将“保留空值”设置为 true。在目标 Table 对象中,我还设置了“保持 Nulls”属性,但是当我运行包时,出现以下错误。

Error: 0xC0202009 at Load HHS Child tables, HHS_GRD_STG Table [579]: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 10.0"  Hresult: 0x80004005  Description: "Unspecified error".
Error: 0xC020901C at Load HHS Child tables, HHS_GRD_STG Table [579]: There was an error with input column "CELL_TXT" (659) on input "OLE DB Destination Input" (592). The column status returned was: "The value violated the integrity constraints for the column.".
Error: 0xC0209029 at Load HHS Child tables, HHS_GRD_STG Table [579]: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "input "OLE DB Destination Input" (592)" failed because error code 0xC020907D occurred, and the error row disposition on "input "OLE DB Destination Input" (592)" specifies failure on error. An error occurred on the specified object of the specified component.  There may be error messages posted before this with more information about the failure.
Error: 0xC0047022 at Load HHS Child tables, SSIS.Pipeline: SSIS Error Code DTS_E_PROCESSINPUTFAILED.  The ProcessInput method on component "HHS_GRD_STG Table" (579) failed with error code 0xC0209029 while processing input "OLE DB Destination Input" (592). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.  There may be error messages posted before this with more information about the failure.

我注意到文件的第一条记录已成功传输到 dest 表。这是具有 NON NULL 值的记录。

由于 Destination 表允许 CELL_VAL 列为空,为什么此任务会失败?

[CELL_VAL] [decimal](14, 4) NULL,

跟进问题:

William 指出,当列不允许 NULL 时,另一个列包含空值是正确的。

这是因为我的包似乎没有区分空字符串值

,"",

和一个 NULL 值

,,

为此,我指定我的文件使用双引号作为文本分隔符,但它似乎没有帮助。结果,由于“保留 NULLS”的设置似乎是一个文件级别的属性,当我真正想要的是将其他列设置为当我有一个由两个连续文本分隔符表示的值时,长度为零的字符串。

是否可以让 SSIS 区分 NULL 和零长度字符串值?

4

1 回答 1

2

在我看来,您显示的错误不是关于 CELL_VAL 列,而是关于 CELL_TXT。

There was an error with input column "CELL_TXT" (659) on input "OLE DB Destination
Input" (592). The column status returned was: "The value violated the integrity 
constraints for the column.".

这似乎表明 CELL_TXT 列存在外键关系或其他一些约束,因此不允许使用空白值。

它与 CELL_VAL 中的空值无关。

于 2013-01-15T19:37:25.967 回答