Курсоры против цикла while - SQLServer

Допустим, у меня есть набор строк в БД (в данном случае SQLServer 2008), которые можно использовать для создания уравнений.

 -----------------------------------------------------
 OperationID | EquationID | Operation | Amount | Order
 -----------------------------------------------------
     1       |     1      |     +     |   12   |  1 
     2       |     1      |     +     |   12   |  2 
     3       |     2      |     /     |   2    |  3 
     4       |     2      |     +     |   12   |  1 
     5       |     2      |     -     |   2    |  2 
 -----------------------------------------------------

Мне нужно найти способ оценить уравнения в этой таблице.

Уравнение 1: 12 + 12 = 24
Equation 2: (12 - 2)/2 = 5

I cannot think of a way to get these results without iterating through the rows. The only ways I know how to do this is with a cursor or through the use of a temp table and a while loop. Are there any better ways to do this? If not generally what will perform better cursors or while loops?

Note: This is somewhat simplified and at this stage in the project we can only conjecture about what the data will look like. The assumption is that each 'equation' will have around 100 to 1000 operations and that there will be a few thousand 'equations' each day that will need to be processed.

6
задан sirchristian 26 October 2010 в 19:58
поделиться