• scarlam (10/24/2012)


    Hi All,

    I have a table containing about 1mil records that i need to loop through, find associated records and insert in another table to create a file.

    For example in the data sample below, if current row serial is one of (VC8, VC1,) then sum amount in rows below to equal amount of current amount value. then insert those associated records to a temp table

    SerialPartIDAmount

    VC8PC545 4,474.23

    VC00586 225.00

    VC00516 2,550.00

    VC00421 40.00

    VC9277 19.23

    VC00815 1,620.00

    vc00206 20.00

    VC1133 348.76

    VC9436 75.00

    VC9534 273.76

    VC1133 945.25

    VC9854 945.25

    VC1826 40.00

    VC8147 40.00

    VC1754 5,131.70

    VC4PC545 3,101.70

    VC9978 2,030.00

    Any ideas on how to go about writing a script or stored procedure that can loop through this table. your help is greatly appreciated.

    You have nothing in the given data to guarantee the order of the rows. You cannot rely on a "naturally" occurring order.

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