moving rows

  • Hi Guru's

    Is there any chance to move the particular rows from one table to other...?if yes..how do we do that..?

    Thanx in advance..

  • if you're making a new table:

    select *

    into DestinationTable

    from SourceTable

    where Expression

    If the destination table already exists:

    insert into DestinationTable

    select *

    from SourceTable

    where Expression

    where:

    DestinationTable is the new table you want to move the records into.

    SourceTable is the table you are coping the rows from.

    Expression is the list of Field=Value for the rows that you want to copy.

    If you then want to delete the rows from the source table, you will need to follow this up with:

    delete from SourceTable where Expression

    All of this information is available by reading Books Online (BOL), the SQL Server Help System. You can access it by pressing the {F1} function key while in SQL Server Management Studio (SSMS). Just highlight the word "select" in a query window, and press {F1}.

    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

  • dineshbornleo (7/4/2009)


    Hi Guru's

    Is there any chance to move the particular rows from one table to other...?if yes..how do we do that..?

    Thanx in advance..

    A better question would be, why do you want to do this? Are you trying to archive rows or what?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (7/4/2009)


    dineshbornleo (7/4/2009)


    Hi Guru's

    Is there any chance to move the particular rows from one table to other...?if yes..how do we do that..?

    Thanx in advance..

    A better question would be, why do you want to do this? Are you trying to archive rows or what?

    +1 ..... More information will usually yield you a better answer.

Viewing 4 posts - 1 through 3 (of 3 total)

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