Hi Here formatted codeDECLARE @datetoday DATETIMEDECLARE @datepast90 DATETIMEDECLARE @POOutstanding VARCHAR(20)SET @datetoday = '2009/07/24'SET @datepast90 = '2009/04/24'SET @POOutstanding = 'POILO-00181'SELECT A.code , A.name1 , A.StandardCost , ISNULL(SUM(B.Qty),0) AS ENDING_INVENTORY, ISNULL(SUM(B.Amount),0) AS AMOUNT , ISNULL(SUM(C.REMAINQTY),0) AS PENDING , ISNULL(SUM(B.Qty),0) + ISNULL(SUM(C.REMAINQTY),0)AS TOTALINVENTORY , ISNULL(SUM(E.QTY),0) AS '90DAYSOFFTAKE' , ISNULL(SUM(E.Amount),0) AS 'SUM_AMOUNT' , ISNULL(SUM(E.Qty),0)/90 AS 'AVERAGE_OFFTAKE'FROM A LEFT JOIN B ON B.ITEMCODE = A.CODE AND B.SHELFCODE LIKE '001' LEFT JOIN C ON C.ITEMCODE = A.code AND C.REMAINQTY <> 0 AND C.TRANSSTATE = 0 AND C.ISCANCEL = 0 AND C.docNO >= @POOutstanding LEFT JOIN D ON C.DocNo = D.DocNo AND D.POSTATUS<> 2 LEFT JOIN E ON A.code = E.ITEMCODE AND E.DOCDATE BETWEEN @datepast90 AND @datetodayGROUP BY A.code , A.name1 , A.StandardCost --Remove comma here. ORDER BY A.code
-------------------------R..