How do I add rows to a table from another table without using Union?

  • Hi guys

    I need to update my main table with the current quarter.

    The two tables have got exactly same columns.

    I can achieve it using union all but then I have to create a different table which contains all these figures.

    Could you guys suggest me a query wherein I just have to update my main table with the new rows?

    Thanks

  • If you have TableA, and TableB - do you want to UPDATE existing rows in TableA with data from TableB, or INSERT new Rows from TableB to TableA, or (as could be the case) UPDATE where an equivalent row exists and INSERT where no equivalent row exists.

  • Hi there,

    you need an INSERT with a SELECT clause.

  • Hi Tim

    Basically I want to insert all rows from table B to table A

  • Nuts (5/27/2009)


    Hi Tim

    Basically I want to insert all rows from table B to table A

    Okay..... try this:

    insert into TableA

    select * from TableB

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • Thanks Guys

    It works fine

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

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