2 Replies

The problem with your query was the wrong WHERE clause placement and not aliasing the subqueries output. I hope this will help
SELECT Product_Code
, ISNULL(Opening_stock, 0) AS OpeStock
FROM Opening_Stock O
LEFT JOIN ( SELECT Product_Code
, ISNULL(SUM(Quantity), 0) RQ
FROM Grn_Detail R
WHERE Product_Code = 2
AND Grn_Date