2

我在从平面文件导入数据到 SQL Server 数据库时遇到了一个奇怪的问题。问题是在某些字段中,既有整数也有字符串,例如 9012635 和 54Z2534、234-1823。

在我所有字段的 SSIS 包中都有一个数据类型 pf DT_WSTR (255),并且数据正在插入到 nvarchar(255) 中。最初,我使用导入导出向导创建了包,然后进行了修改(但没有对转换进行修改。我接受了向导给出的内容(即 DT_WSTR)。它最终没有将数据导入这些字段。它创建了行并将数据插入其他列,但在某些列中,它放置 NULL - 没有数据。

为了测试事情,我最终尝试使用该文件的向导。我收到错误消息:“采样数据中的最后一行不完整。列或行分隔符可能丢失或文本限定不正确”。

尽管如此,该文件仍会导入所有的行,但似乎不喜欢这些列中的文本,并且最终将整数值作为文本导入。

其他没有给出此错误消息的文件也有相同的症状。

我不知道如何解决这个问题,或者问题是什么。

4

1 回答 1

7

NVARCHAR should correspond to DT_WSTR, and VARCHAR should correspond to DT_STR. Are you sure it's not a conversion problem between those two types? If you have true DT_I4 integers coming in, you should not be seeing alpha characters.

You can add a Data Viewer to your dataflow to ascertain exactly what data types you have in your SSIS package.

If you wish to convert string types, you can use a Derived Column Transform to create a new column, and then cast one string type into another.

So, for example, (DT_STR, 30, 1252)OldColumnName would cast thirty characters of an NVARCHAR to VARCHAR according to code page 1252. Alternatively, (DT_WSTR, 50)ColName would cast fifty characters of VARCHAR into NVARCHAR.

于 2013-04-15T19:28:37.917 回答