我正在试图向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,
你是指“在SSIS中运行此代码”的含义?它看起来像T-SQL代码,所以我猜测它在提供OLE DB源的SQL查询中?如果这是它的原因,那么它不是你引用的代码引起的问题(SSIS不执行那个)。问题在于输出列“Id”是错误的数据类型。查看SSIS中的高级编辑器以查看它的数据类型(SSIS经常猜测错误) – SebTHU
DECLARE @f FLOAT = 443400。253243 SELECT'ABC'+ cast(cast(@f AS INT)as VARCHAR(10))在ssms中运行时没有任何错误 – StackUser
根据@SebTHU,错误位于OLE DB Source的输出列中。没有固定数据类型的源列使得SSIS可以根据结果猜测数据类型。为防止出现这种情况,必须在源查询中指定一个固定的数据类型:CAST('ABC'+ CAST(CAST(KL.ID as INT)as CHAR(46)))AS CHAR(50)' – Balde