SELECT CASE MarkingDetail.StatusEditRequis WHEN 'False' THEN MarkingDetail.StatusEditRequis END AS TotalRequis, Stocks.CategoryName,
Stocks.PRODUCT, Stocks.GradName, Stocks.MATW, Stocks.MATL, Stocks.MATH, Stocks.MATT, Stocks.WeightSize, Stocks.Color, Stocks.UNIT,
Stocks.Remark, Stocks.Strong, MarkingDetail.StatusEditRequis, Stocks.Amount - MarkingDetail.Amount_Requis AS StockAmount_Requis,
Stocks.Amount, Sum(MarkingDetail.Amount_Requis)As Amount_Requis ' ตรงนี้จะ sum ทำไม่ได้เพราะว่ามีค่า Null อยากให้ค่า null เป็น 0 ทำยังไง ถ้าเป็น 0ได้ ผมว่าน่าจะ Sum ได้
FROM Stocks LEFT OUTER JOIN
MarkingDetail ON Stocks.PRODUCT = MarkingDetail.Product
ORDER BY Stocks.PRODUCT
SELECT CASE MarkingDetail.StatusEditRequis WHEN 'False' THEN MarkingDetail.StatusEditRequis END AS TotalRequis, Stocks.CategoryName,
Stocks.PRODUCT, Stocks.GradName, Stocks.MATW, Stocks.MATL, Stocks.MATH, Stocks.MATT, Stocks.WeightSize, Stocks.Color, Stocks.UNIT,
Stocks.Remark, Stocks.Strong, MarkingDetail.StatusEditRequis, Stocks.Amount - MarkingDetail.Amount_Requis AS StockAmount_Requis,
Stocks.Amount, ISNULL(Sum(MarkingDetail.Amount_Requis),0) As Amount_Requis ' ลองใส่ ISNULL แล้วได้ไหม
FROM Stocks LEFT OUTER JOIN
MarkingDetail ON Stocks.PRODUCT = MarkingDetail.Product
ORDER BY Stocks.PRODUCT
SELECT CASE MarkingDetail.StatusEditRequis WHEN 'False' THEN ISNULL(MarkingDetail.Amount_Requis, 0) END AS Total, Stocks.PRODUCT,
Stocks.GradName, Stocks.MATW, Stocks.MATL, Stocks.MATH, Stocks.MATT, Stocks.WeightSize, Stocks.Color, Stocks.UNIT, Stocks.Remark,
Stocks.Strong, SUM(ISNULL(Stocks.Amount - MarkingDetail.Amount_Requis, 0)) AS StockAmount_Requis, Stocks.Amount,
ISNULL(MarkingDetail.Amount_Requis, 0) AS Amount_Requis
FROM Stocks LEFT OUTER JOIN
MarkingDetail ON Stocks.PRODUCT = MarkingDetail.Product
GROUP BY Stocks.CategoryName, Stocks.PRODUCT, Stocks.GradName, Stocks.MATW, Stocks.MATL, Stocks.MATH, Stocks.MATT, Stocks.WeightSize,
Stocks.Color, Stocks.UNIT, Stocks.Remark, Stocks.Strong, Stocks.Amount, MarkingDetail.StatusEditRequis, MarkingDetail.Amount_Requis
ORDER BY Stocks.PRODUCT