Aruna Raghunam Aruna Raghunam - 3 months ago 16
SQL Question

Merge data from 2 tables into one

I have Employees and Non Employees tables (data is being imported from views).

Now, I need to create a single table which holds both Employee and Non Employee data. I am unable to progress from here.

I am getting this error when I try it using import-export task:

DataMappingError


  • Executing (Error)


    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)


Answer

First Create by script a new table with the column that you want.

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

After this, made a Insert with selecting the your old tables.

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

And Create an index to improve performance at your most queried column.

Comments