What I want is an INSERT where in my query parameter I will pick a fruit and a QTY and it wil give me the exact QTY broken down by lot and by LOWEST COST first. The resulting table (TABLE2) should look like this if I were to pick Apple and 500 as the QTY.

Fruit | Qty | CostApple | 200 | 1.45Apple | 300 | 3.75

As you can see, I get my exact 500 apples and it's in lowest cost first. AND it knows to only bring 300 out of the 400 because I only need 300 to get to my 500.

Another example is if I were to pick Oranges and 250 for QTY, this is what I should get for TABLE 2.

Fruit | Qty | CostOrange | 100 | 5.65Orange | 150 | 7.90

Again, it knows I only need 150 out of the 500 to complete my 250.

Is this even possible in some kind of a query?

------------------------------Using VS2010 / Learning in VB.Net / Win2008 R2 / SQL 2008 R2Be kind to the newbies because you were once there.