Inventory Price Calculation in SQL
===

I'm in SQL 2005 and I'm trying to convert this Cursor into something that isn't a Cursor to determine if this is the most efficient way to do this.

        	--Create cursor to determint total cost
    DECLARE CostCursor CURSOR FAST_FORWARD
            FOR SELECT  ReceiptQty
                       ,Price
                FROM    @temp_calculate
                ORDER BY UpdateDate DESC
    OPEN CostCursor 
    FETCH Next FROM CostCursor INTO @ReceiptQty,@Price
    WHILE @@FETCH_STATUS = 0
          BEGIN
                IF @OnHandQty >= @ReceiptQty
                   BEGIN
    						   --SELECT @ReceiptQty,@Price, 1,@OnHandQty
                         SET @Cost = @ReceiptQty * @Price
                         SET @OnHandQty = @OnHandQty - @ReceiptQty
                         SET @TotalCost = @TotalCost + @Cost
                   END
                ELSE
                   BEGIN
                         IF @OnHandQty < @ReceiptQty
                            BEGIN
    							  SELECT @ReceiptQty,@Price, 2,@OnHandQty
                                  SET @Cost = @OnHandQty * @Price
                                  SET @OnHandQty = 0
                                  SET @TotalCost = @TotalCost + @Cost
    							  BREAK;
                            END
                   END
                FETCH Next FROM CostCursor INTO @ReceiptQty,@Price
          END
    CLOSE CostCursor
    DEALLOCATE CostCursor

The system needs to go through and use the newest recieved inventory and price to determine what the paid for the on-hand is.

Ex. 1st Iteration: @OnHandQty = 8 RecievedQty = 5 Price = 1 UpdateDate = 1/20 Results:  @HandQty = 3 @TotalCost = $5
2nd Iteration: @OnHandQty = 3 RecievedQty = 6 Price = 2 UpdateDate = 1/10 Results:  @HandQty = 0 @TotalCost = $11

The Final Results tell me that the inventory I have on hand I paid $11 for.  If I was doing this in C# or any other Object Oriented langauge this screams Recursion to me.  I thought about a Recursive CTE could be more efficient.  I've only successfully done any Recursive CTE's for Heirarchy following types of Queries and I haven't been able to successfully wrap my head around a query that would achieve this another way.

Any help or a simple thats how it has to be would be appreciated.