How to update a column which is coming from two different sources?

  • Hi Everyone,

    Scenario:I have to populate the records from two different sources into one table.

    Now- One column is added in both sources.

    I need to bring that column records as well from those two sources into one table.

    so how to update the column which is coming from 2 sources??

  • How is the data coming? IS it in SQL Server?

  • Yes..data is coming from sql server databases only..

  • i'd simply insert from a UNION of the two alternate sources;

    insert into Table1(alotofcolumns)

    select alotofcolumns from Server1.Database.dbo.Source1Table WHERE criteria=1

    union

    select alotofcolumns from Server2.Database.dbo.Source2Table WHERE criteria=1

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks for the reply..

    But the thing is...something different..

    let me put it on..

    I am having the table named TABLE-A in Server1 and TABLE-B in Server2.

    I already pulled the records from these two tables into another server Server3's TABLE-C by doing as you mentioned(By Union ALL).

    Now, In both sources i.e TABLE-A and in TABLE-B, one new column get added. So I altered the TABLE-C by adding one more column.

    Now How can I update this column with the values coming from those two tables i.e TABLE-A and TABLE-B into TABLE-C.

  • it's just an update instead of an insert....but there has to be something to join the data...an ID column or some other criteria.

    you should really ALWAYS post the real table definition, along with some sample data....

    theoretical "TABLE A AND TABLE B gets you incomplete or non specific answers.

    UPDATE TABLE-C

    SET TABLE-C.NEWCOLUMN = SUBALIAS.NEWCOLUMN

    FROM (SELECT TABLE-A.lotsofcolumns from TABLE-A

    UNION

    SELECT TABLE-B.lotsofcolumns from TABLE-B

    ) SUBALIAS

    WHERE TABLE-C.ID = SUBALIAS.ID

    md.noorullah (1/21/2009)


    Thanks for the reply..

    But the thing is...something different..

    let me put it on..

    I am having the table named TABLE-A in Server1 and TABLE-B in Server2.

    I already pulled the records from these two tables into another server Server3's TABLE-C by doing as you mentioned(By Union ALL).

    Now, In both sources i.e TABLE-A and in TABLE-B, one new column get added. So I altered the TABLE-C by adding one more column.

    Now How can I update this column with the values coming from those two tables i.e TABLE-A and TABLE-B into TABLE-C.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • sorry and thanks again..

    Yeah I have to join on one ID Column and at the same time I need to make sure that there will not be duplicates in the target table as the two source tables contain same ID in their respective tablles

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply