• sqlblue (1/5/2009)


    Can I do batch insert or update with a set of rows at a time(does not have to be in order of any kind), and have it automatically go to the next set of rows that have not been inserted or updated? If so, how can I do it?

    thanks for any help.

    Below is my script. The insert is for several millions records, and so I

    break it down by filenumber but it is still big for insert,

    so I try to do it in a small set.

    insert into table2 (col1, col2, col3)

    select table1.col1, table1.col2, table3.col3

    from table1 inner join table3

    on table1.col1 = table3.col1

    where table1.filenumber = 1

    go

    insert into table2 (col1, col2, col3)

    select table1.col1, table1.col2, table3.col3

    from table1 inner join table3

    on table1.col1 = table3.col1

    where table1.filenumber = 2

    go

    "Break it down by file number..." So, why aren't you doing it that way? 😉 Do a distinct on the filenumber and create a control table that has the file numbers in it... then, loop on that. The handy part is, any dates that are created on the way will all have the same date throughout the file.

    --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)