2016-08-17 123 views
-2

我有僱員和非僱員表(正在從視圖導入數據)。將來自2個表的數據合併爲一個

現在,我需要創建一個包含Employee和Non Employee數據的表。我無法從這裏進步。

我得到這個錯誤,當我嘗試使用進出口任務:

DataMappingError

  • 執行(錯誤)

    Messages • Error 0xc02020c5: Data Flow Task 1: Data conversion failed while converting column "Unit Number" (44) to column "Unit Number" (101). The conversion returned status value 2 and status text "The value could not be converted because of a potential loss of data.". (SQL Server Import and Export Wizard) • Error 0xc0209029: Data Flow Task 1: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "Data Conversion 0 - 0.Outputs[Data Conversion Output].Columns[Unit Number]" failed because error code 0xC020907F occurred, and the error row disposition on "Data Conversion 0 - 0.Outputs[Data Conversion Output].Columns[Unit Number]" 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. (SQL Server Import and Export Wizard) Error 0xc0047022: Data Flow Task 1: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Data Conversion 0 - 0" (85) failed with error code 0xC0209029 while processing input "Data Conversion Input" (86). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure. (SQL Server Import and Export Wizard)

回答

2

首先通過腳本的新表創建與你想要的列。

CREATE TABLE dbo.Employees (
    COLUMN_A TYPE, 
    COLUMN_B VARCHAR(100) 
); 

之後,做了一個插入選擇你的舊錶。

INSERT INTO dbo.Employees (COLUMN_A, COLUMN_B) 
    SELECT COLUMN_A, COLUMN_B FROM TABLE1 UNION ALL 
    SELECT COLUMN_A, COLUMN_B FROM TABLE2; 

並創建一個索引以提高查詢最多的列的性能。

+0

以上查詢是否會擺脫重複? –

+0

我ram上面查詢並獲取此錯誤:不允許從數據類型varchar(max)到varbinary(max)的隱式轉換。使用CONVERT函數來運行此查詢。 –

1

查看詳細信息後,似乎「單元號」列有不同的數據類型。 爲了克服這個問題,要麼使數據類型與表中的數據類型相同,要麼創建一個具有高數據類型的新表,然後存在一個(意思是如果你的表有小int,小int),那麼公用表將具有數據類型smallint。

+0

所以在這種情況下我有Unit Number作爲int和其他tablea varchar(1)。任何想法常見的表格數據類型應該是什麼? –

+0

如果是這種情況,那麼最好的辦法是保持每個列爲VARCHAR,並且一旦確認特定列具有特定的數據類型,然後在int,tinyint,smallint等中相應地更改。 –

1

將varbinary類型的行插入varchar或任何其他數據類型時,會導致隱式轉換問題。首先確定哪個列被定義爲varbinary並使用cast作爲cast(column_name作爲varchar(100)),問題將被解決。

+0

我嘗試了CONVERT(varchar(MAX), PictureName,2)但它不工作:( –

+0

嘗試cast(PictureName as varchar(max))。它應該工作 –

1

爲什麼你使用導入導出嚮導?

如果你的表和視圖都在同一個數據庫中,你可以做以下操作:

INSERT INTO TABLE 
SELECT COL1, COL2....FROM VIEW 

如果您使用的導入導出任務,確保源和目標的數據類型和長度匹配(用於CHAR/VARCHAR/NCHAR如果目標列長度小於源,則可能會發生/ nvarchar截斷)。

+0

是的我有2個視圖在同一個數據庫中是否有可能從2個不同的視圖插入數據到單個表使用以上查詢? –

+0

是的,開發你的T-SQL首先結合你的視圖,並遵循上面的語法 – p2k

+0

這樣的工作!謝謝..但有一個問題:第一個表有varbinary圖片名稱,並在轉換爲varchar後,我看到ÿØÿà.. –

相關問題