• Sigerson (8/28/2013)


    I respect the general wisdom about not using cursors and loops and have usually found a way to avoid them.

    But I have one data upload from a vendor in a CSV file. I pull it into a temp table in SS with an SSIS process, which then runs a stored procedure. The SP creates a cursor and loops through the temp file, evaluating the vendor's returned data. Depending on the content of each data point, I may write one thing to one table or another value to a different table.

    I don't know how I could possible build all that updating logic into any simpler form and it works well enough and quickly enough for me.

    So it seems to me there are times that a cursor and a loop are the only possible solutions. But I'm always ready to learn.

    Can anyone point me toward a discussion of why and how all cursors and loops can be done away with?

    I know very little of SSIS. If I were doing this in T-SQL, I'd simply add a column that identified which table I'd want the row to go to. Then I'd do a single pass "INSERT" for each table. I don't know how you are evaluating which rows go to what table but even 5 passes because you have 5 tables is going to be an awful lot faster than using a loop against a file.

    Think "columns", not "rows".

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