我正在試圖向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