Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8372

Re: Weekly stock forecasting report query

$
0
0

Okay, please give this a try:

 

/* SELECT * FROM OINV i */

DECLARE @FROM AS DATETIME

DECLARE @TO AS DATETIME

SET @FROM = /* i.DocDate */ [%0]

SET @TO = /* i.DocDate */ [%1]

 

DECLARE @NrOfDays AS INT = DATEDIFF(DAY, @FROM, @TO)

DECLARE @NrOfWeeks AS DECIMAL = @NrOfDays / 7

 

select i.ItemCode

      ,i.ItemName

      ,ISNULL(s.Quantity, 0) AS SalesTotal

      ,(ISNULL(s.Quantity, 0) / @NrOfWeeks) AS AvgSalesPerWeek

      ,i.OnHand AS InStock

      ,CAST(CASE

             WHEN (ISNULL(s.Quantity, 0) / @NrOfWeeks) <= 0 THEN 999

             ELSE ROUND(i.OnHand / CASE

                                    WHEN (ISNULL(s.Quantity, 0) / @NrOfWeeks) = 0 THEN 1

                                    ELSE (ISNULL(s.Quantity, 0) / @NrOfWeeks)

                                   END, 2)

            END AS MONEY) AS StockWillLastThisManyWeeks

from OITM i

     left outer join (select r.itemcode

                            ,Sum(r.Quantity) AS Quantity

                      from INV1 r

                           inner join OINV h on r.DocEntry = h.DocEntry

                      where h.DocDate between @FROM and @TO

                      group by r.ItemCode) s on i.ItemCode = s.ItemCode

where i.OnHand <> 0

OR ISNULL(s.Quantity, 0) <> 0

 

Regards,

Johan


Viewing all articles
Browse latest Browse all 8372

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>