B
bigness
Unregistered / Unconfirmed
GUEST, unregistred user!
SELECT Product_1.s_ID as Prod_ID, a.Stor_ID, SUM(a.Prod_Number2) AS Prod_Number2, SUM(a.Prod_Number1)
AS Prod_Number1, convert(numeric(20,6) ,case when SUM(a.Prod_Number2) <> 0 then SUM(a.CostMoney) / SUM(a.Prod_Number2) else 0 end) AS CostPrice, SUM(a.CostMoney) AS CostMoney
FROM dbo.Product Product_1 CROSS JOIN
(SELECT Product.s_ID, Product.u_Code, Product.s_ParentID, s_FullID,
Stor_ID, SUM(StorageIni.Prod_Number1) AS Prod_Number1,
SUM(StorageIni.Prod_Number2) AS Prod_Number2,
SUM(CostMoney) CostMoney
FROM StorageIni INNER JOIN
Product ON StorageIni.Prod_ID = Product.s_ID
GROUP BY Product.s_ID, Product.u_Code, Product.s_ParentID,
Product.s_FullID, Stor_ID) a
WHERE (a.s_FullID LIKE Product_1.s_FullID + '%')
GROUP BY Product_1.s_ID, Product_1.u_Code, Product_1.u_Name,
Product_1.s_FullID, Product_1.ProdDW, Product_1.ProdSpec, Product_1.ProdType,
Product_1.ProdArea, Product_1.BarCode, a.Stor_ID
AS Prod_Number1, convert(numeric(20,6) ,case when SUM(a.Prod_Number2) <> 0 then SUM(a.CostMoney) / SUM(a.Prod_Number2) else 0 end) AS CostPrice, SUM(a.CostMoney) AS CostMoney
FROM dbo.Product Product_1 CROSS JOIN
(SELECT Product.s_ID, Product.u_Code, Product.s_ParentID, s_FullID,
Stor_ID, SUM(StorageIni.Prod_Number1) AS Prod_Number1,
SUM(StorageIni.Prod_Number2) AS Prod_Number2,
SUM(CostMoney) CostMoney
FROM StorageIni INNER JOIN
Product ON StorageIni.Prod_ID = Product.s_ID
GROUP BY Product.s_ID, Product.u_Code, Product.s_ParentID,
Product.s_FullID, Stor_ID) a
WHERE (a.s_FullID LIKE Product_1.s_FullID + '%')
GROUP BY Product_1.s_ID, Product_1.u_Code, Product_1.u_Name,
Product_1.s_FullID, Product_1.ProdDW, Product_1.ProdSpec, Product_1.ProdType,
Product_1.ProdArea, Product_1.BarCode, a.Stor_ID