SELECT DISTINCT
Stocks.PRODUCT, SUM(ISNULL(CASE MarkingDetail.StatusEditRequis WHEN 'False' THEN MarkingDetail.Amount_Requis END, 0)) AS Requis,
Stocks.GradName, Stocks.WeightSize, Stocks.Color, Stocks.UNIT, Stocks.Remark, (Stocks.Amount - ISNULL(CASE MarkingDetail.StatusEditRequis WHEN 'False' THEN MarkingDetail.Amount_Requis END, 0))
AS StockAmount_Requis, Stocks.Amount, SUM(ISNULL(MarkingDetail.Amount_Requis, 0)) AS Amount_Requis, Stocks.MATW, Stocks.MATL,
Stocks.MATT, Stocks.Strong
FROM Stocks LEFT OUTER JOIN
MarkingDetail ON Stocks.PRODUCT = MarkingDetail.Product
GROUP BY Stocks.CategoryName, Stocks.PRODUCT, Stocks.GradName, Stocks.WeightSize, Stocks.Color, Stocks.UNIT, Stocks.Remark, Stocks.Amount,
Stocks.MATW, Stocks.MATL, Stocks.MATT, Stocks.Strong
ORDER BY Stocks.PRODUCT
SELECT DISTINCT
Stocks.PRODUCT, SUM(ISNULL(CASE MarkingDetail.StatusEditRequis WHEN 'False' THEN MarkingDetail.Amount_Requis END, 0)) AS Requis,
Stocks.GradName, Stocks.WeightSize, Stocks.Color, Stocks.UNIT, Stocks.Remark, SUM(Stocks.Amount + - ISNULL(CASE MarkingDetail.StatusEditRequis WHEN 'False' THEN MarkingDetail.Amount_Requis END, 0))
AS StockAmount_Requis, Stocks.Amount, SUM(ISNULL(MarkingDetail.Amount_Requis, 0)) AS Amount_Requis, Stocks.MATW, Stocks.MATL,
Stocks.MATT, Stocks.Strong
FROM Stocks LEFT OUTER JOIN
MarkingDetail ON Stocks.PRODUCT = MarkingDetail.Product
GROUP BY Stocks.CategoryName, Stocks.PRODUCT, Stocks.GradName, Stocks.WeightSize, Stocks.Color, Stocks.UNIT, Stocks.Remark, Stocks.Amount,
Stocks.MATW, Stocks.MATL, Stocks.MATT, Stocks.Strong
ORDER BY Stocks.PRODUCT