2016-03-15 75 views
0

我正在试图向SSIS(OLE DB Source)中的数据添加3个字母。我的数据源格式是浮动,所以首先我投它为int,旁边烧焦并添加到字符串:在SSIS中铸造

'ABC'+cast(cast(KL.ID as int) as char(46)) Id

,我在MS 2008R2像

ABC443400

得到,但是当我运行这段代码在SSIS中,我得到:

[OLE DB Source [1]] Error: There was an error with output column "Id" (37) on output "OLE DB Source Output" (11). The column status returned was: "The value could not be converted because of a potential loss of data.".

[OLE DB Source [1]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "output column "Id" (37)" failed because error code 0xC0209072 occurred, and the error row disposition on "output column "Id" (37)" 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.

[SSIS.Pipeline] Error: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on component "OLE DB Source" (1) returned error code 0xC0209029. The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing. There may be error messages posted before this with more information about the failure.

在OLE DB源的高级编辑器:

External Columns: DataType - string[DT_STR], Length - 49, Output Columns: DataType - double-precision float[DT_R8]

在OLE DB目标的高级编辑器:

External Columns: DataType - string[DT_STR], Length - 50,

+2

你是指“在SSIS中运行此代码”的含义?它看起来像T-SQL代码,所以我猜测它在提供OLE DB源的SQL查询中?如果这是它的原因,那么它不是你引用的代码引起的问题(SSIS不执行那个)。问题在于输出列“Id”是错误的数据类型。查看SSIS中的高级编辑器以查看它的数据类型(SSIS经常猜测错误) – SebTHU

+0

DECLARE @f FLOAT = 443400。253243 SELECT'ABC'+ cast(cast(@f AS INT)as VARCHAR(10))在ssms中运行时没有任何错误 – StackUser

+0

根据@SebTHU,错误位于OLE DB Source的输出列中。没有固定数据类型的源列使得SSIS可以根据结果猜测数据类型。为防止出现这种情况,必须在源查询中指定一个固定的数据类型:CAST('ABC'+ CAST(CAST(KL.ID as INT)as CHAR(46)))AS CHAR(50)' – Balde

回答

1

看着你的最新更新。 OLEDB目标列类型不应该是相关的(尽管它稍后可能会变得相关),因为错误发生在OLEDB源上。

问题出在OLEDB Source Output Columns:Id被定义为double(RT_8)。在高级编辑器中,您可以更改外部列“Id”的数据类型(如果您对当前设置感到满意 - 看起来很好:49个字符 - 然后将其更改为其他内容,然后再返回)。这应该也会自动更新输出列类型(但检查并手动更改以匹配)。

更进一步,听起来好像您正在将此列写入OLEDB Dest。您可能必须将目标表中的列类型更改为varchar(50)或nvarchar(50)(与SSIS内部“Id”列类型相匹配),并让SSIS再次读取表元数据 - 或使用Advanced强制更改类型编辑。一旦更改了源中的列类型,SSIS 应该抱怨OLEDB Dest中存在类型不匹配,但我不能保证这一点!

我认为,SSIS从一开始就会猜测Id列的错误类型。

0

它看起来像你在OLE DB源直接编写SQL代码。这似乎是与您正在使用的列ID相关的元数据的问题。

在OLE DB Source的高级设置中检查数据类型和/或字符串的长度。

0

我解决这个使用派生列:

"ABC" + (DT_STR,47,1250)Id

和数据转换:

string[DT_STR], 50

但有可能只使用SQL办呢?