Subject | Re: [firebird-support] Re: First-In-First-Out (FIFO) stock valuation |
---|---|
Author | Venus Software Operations |
Post date | 2011-03-05T07:01:41Z |
On 04/03/2011 06:06, José Manuel wrote:
suggest SPs.
Thanks a lot José. Below is adapted to my real life:
Kind regards
Bhavbhuti
SELECT SUM(qty * bRate) AS bValuation
FROM (SELECT IIF(bQty + qtyOut >= 30 /*current stock */
, (30 /*current stock */ - qtyOut)
, bQty) as qty
, bRate
FROM (SELECT sPurchaseBillItem.bQty
, sPurchaseBillItem.bRate
, COALESCE((SELECT SUM(PurchaseBillItemInner.bQty)
FROM sPurchaseBillItem AS
PurchaseBillItemInner
JOIN tPurchaseBill AS
PurchaseBillInner
ON
PurchaseBillInner.iID = PurchaseBillItemInner.iPID
WHERE (PurchaseBillInner.tDt >
tPurchaseBill.tDt AND PurchaseBillItemInner.iItemID = 9 /* item id */))
, 0)as qtyOut
FROM tPurchaseBill
JOIN sPurchaseBillItem
ON sPurchaseBillItem.iPID = tPurchaseBill.iID
AND sPurchaseBillItem.iItemID = 9 /*
item id */) AS PurchaseBillsIntermediate
WHERE (qtyOut <= 30 /*current stock */)) AS PurchaseBillsFIFO
>Amazing what can just SQL do!!!! I had expected all the people to only
>
> I did something similar in the past. I hope the performance is
> sufficient for you.
> < chomp >
> José Manuel Sanjuán.
>
suggest SPs.
Thanks a lot José. Below is adapted to my real life:
Kind regards
Bhavbhuti
SELECT SUM(qty * bRate) AS bValuation
FROM (SELECT IIF(bQty + qtyOut >= 30 /*current stock */
, (30 /*current stock */ - qtyOut)
, bQty) as qty
, bRate
FROM (SELECT sPurchaseBillItem.bQty
, sPurchaseBillItem.bRate
, COALESCE((SELECT SUM(PurchaseBillItemInner.bQty)
FROM sPurchaseBillItem AS
PurchaseBillItemInner
JOIN tPurchaseBill AS
PurchaseBillInner
ON
PurchaseBillInner.iID = PurchaseBillItemInner.iPID
WHERE (PurchaseBillInner.tDt >
tPurchaseBill.tDt AND PurchaseBillItemInner.iItemID = 9 /* item id */))
, 0)as qtyOut
FROM tPurchaseBill
JOIN sPurchaseBillItem
ON sPurchaseBillItem.iPID = tPurchaseBill.iID
AND sPurchaseBillItem.iItemID = 9 /*
item id */) AS PurchaseBillsIntermediate
WHERE (qtyOut <= 30 /*current stock */)) AS PurchaseBillsFIFO