• Set based means that you are working on 'sets' of data instead of rows. Anytime you can apply logic or business rules accross a set of common data, you'll way outperform cursoring through each row and working one at a time. Why don't you give us some greater detail as to your setup and schema and then post your cursors. If you provide enough background and setup info, you'll have several experts jump in and help you. What you are trying to do sounds like a pretty basic ETL (Extract-Transform-Load) operation and I've yet to find one that cannot be solved without the use of a Cursor.

    So for your case, you are using a cursor because you have to do different actions depending on how the data looks right? This tells me that you have some sort of business rules that tell you what type of activity you need to perform on that data. Instead of cursoring through each row and deciding what to do with the data based on those rules, why not run one operation for each grouping or set of rows? I may not be comming accross real clear but take this example. Say you have a table that looks like this:

    MyTable

    RoNum RowValue

    1 A

    2 B

    3 C

    4 B

    5 B

    6 A

    Let's say that the RowValues define which set of business rules you are going to use to load this data. The cursor approach says to process all rows one at a time starting with row 1. As soon as the cursor pulls RoNum 1, it says 'Ah ha, this is a type A. I'll run the business logic for this type of row'. It will process RoNum 1 and then move on to RoNum 2 to determine what to do there. This process continues until there are no more rows. Pretty simple right? Well, with set based logic, you would apply your busness logic to each set of data. In this case, your code would process RoNum 1 and 6 at the same time, rows 2, 4, and 5 and the same time, and then row 3.

    Post your cursors and you'll get some help. If you really are open minded to learn, having a cursor re-written as set based for you will get you going down the right path.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden