>A SELECT statement doing this is interesting. Just curious what would happen if the closing stock consists of 2 purchases, ie. purchase of 10 @ 12.50 and another purchase of 10 @ 13.00. Out of which only 5 are sold @ whatever rate. Now the closing stock is 15 out of which 5 is @ 12.50 and 10 is @ 13.00.
>
I asked Tariq to clarify the requirements. He wanted to use the latest rate for the closing stock value. This is what my query is doing. How you'll find out which items were sold otherwise?
In other words, using latest rate is the simplest calculation, although I'm not sure how this problem should be solved in accounting. May be someone who deals with lots of similar problems can show the exact formula to use.
If it's not broken, fix it until it is.
My Blog