Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

SQL FIFO Query

$
0
0

Hello all;

Like others, I need help developing a SQL query to determine A FIFO Cost for parts. I'll make mine easier that others I have read in this forum by limiting it to one table.

I have an Inventory Costing Table that contains data like so...

Part#          Date                 Cost          QuantityProduced

AA001        01/01/2011        .0158        12500

AA001        02/15/2011        .0214        7500

AA001        03/15/2011        .0196        12125

AA001        04/15/2011        .0211        6300

What I need to do is write a query that will return the cost depending on the quantity shipped. For example, this table shows the quantity and cost of parts produced - what I need to know is how to extract the cost if say 25000 parts were shipped. Looking at the table (and doing some math), if 25000 parts were shipped then the FIFO cost would be .0196 for 7125 pieces, .0211 for the next 6300 pieces and so forth  - because the running total of the quantity shipped is less than the running total of the quantity produced in that tier.

How do I write a query that finds the correct Cost if I know the total quantity shipped?

 


Todd Lerew

Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>