2016-03-15 51 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辦呢?