Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Closing Stock Value
Message
 
 
À
06/07/2010 15:37:14
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows XP
Divers
Thread ID:
01471551
Message ID:
01471586
Vues:
34
>And if the item never was purchased - latest from the stock? What if you update your stock from other source (e.g. item in stock has later date when purchased item)?
>
>
>Then Openinge rate will be use

Try:
SELECT O.Codes as [Code], O.Products, ;
OpeningQty as [OpeningQty], ;
PurchaseQty as [PurchaseQty], ;
PurchaseAmount as [PurchaseAmount], ;
OpeningQty + NVL(PurchaseQty,0) as [TotalQty], ;
OpeningAmount + NVL(PurchaseAmount,0) as [TotalAmount], ;
NVL(SoldQty,0) as [SoldQty], ;
NVL(SoldAmount,0) as [SoldAmount], ;
OpeningQty + NVL(PurchaseQty,0) - NVL(SoldQty,0) as [ClosingQty], ;
(OpeningQty + NVL(PurchaseQty,0) - NVL(SoldQty,0)) * IIF(LastStocked > NVL(LastPurchased,{}),LastStockRate, LastPurchaseRate) as [ClosingAmount] ;
 FROM (select Codes, Products, SUM(qty) as OpeningQty, ;
SUM(Amount) as OpeningAmount, MAX(dates) as LastStocked from Open_Stock group by Codes, Products) O ;
INNER JOIN (select Rate as LastStockRate, Codes, Dates FROM Open_Stock) O1 ON O.Codes = O1.Codes AND O.LastStocked = O1.Dates ;
LEFT JOIN (select Codes, Products, ;
SUM(qty) as PurchaseQty, SUM(Amount)  as PurchaseAmount, MAX(Dates) as LastPurchased ;
from Purchase group by Codes, Products) P ;
ON O.Codes = P.Codes ;
LEFT JOIN (select Rate as LastPurchaseRate, Codes, Dates FROM Purchase) P1 on P.Codes = P1.Codes and P.LastPurchased = P1.Dates ;
LEFT JOIN (select Codes, Products, ;
SUM(qty) as SoldQty, SUM(Amount) as SoldAmount ;
from Sales group by Codes, Products) S ;
ON O.Codes = S.Codes
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform