table iteration

  • Hi, I have 2 tables, DataToBeParsed and OrderCatalog

    The first table DataToBeParsed contains several Costs Centers with a few concepts inside like this:

    100

    Salary

    Vacations

    Insurance

    Salary

    101

    Salary

    Vacations

    Insurance

    Salary

    And the OrderCatalog determines the order in which the concepts are supposed to be placed in each CostCenter, like this

    1     Salary

    2     Vacations

    3     Insurance

    4     Salary

    What would be the best way to be checking the order every time I find a new cost center, considering the concept names are repeated and IDs are not available (data is loaded with a dts from .csv SAP generated files)

    Steps would be

    1.- I find cost center 100

    2.- I read the first concept of the cost center and check OrderCatalog to see if that was the concept that was supposed to be next

    3.- Read second concept (Vacations) check OrderCatalog to see if that was next

    4.- Repeat until I find next cost center

    5.- Start from the first row of OrderCatalogs to do the same validation again since order wont change from cost center to cost center

  • May be I'm wrong, but ....

    You could insert all your denormalized data into a temp table and create two cursors. The nested cursor would be the Order table you want to check against.

    First cursor could iterate thorough entire DataToParse, and open the nested one every time you find a non integer so you can set a counter as to check it against the table that contains the Order data. Reset the counter and close the nested cursor when you find a new integer.

     

    sorry if I misunderstood

    Ask for more help if you need it

    cheers!

  • What are the definitions of the tables DataToBeParsed and OrderCatalog?

  •  

    Are Bhai ?

    Teri Problem Meri samazh mein nahi aya ?

    Zara Samjhana To ??

     

     

  • Jesper, DataToBeParsed seems to be one field only.

    It contains denormalized info from two fields, as long as it was loaded from a SAB text migration file

    Working with cursors as I described above should work.

  • If that's the only field, then I'm a bit puzzled as to how you determine when you have a CostCenterID and when you have a CostCenterName. Also, you have no way to control the order of the output in your select (i.e no field to "order by").

    If there is an extra field that determines the order on table DataToBeParsed, then I think it is easy to write a set-based query to solve the problem. And this will always perform better than a cursor-based solution, I think.

     

Viewing 6 posts - 1 through 5 (of 5 total)

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