lundi 18 juillet 2016

a query to retrieve days left for old stock to finish based on 90 days sales history

I have this query from 2 tables 1) SalesLine 2) SalesInvoiceHeader which returns last 90 day sales by item number. Can anyone suggest how to retrieve days left for old stock to finish?

Select
    sl.item_no,
    sl.locationcode,
    sum(sl.qty) / 90 AvgSaleQty
    into #tmpavgsaleqty
FROM [Sales Invoice Header] sih 
join Sales_line sl
  on sih.[Sell-to Customer No_] = sl.[Sell-to Customer No_]
    and sih.locationcode = sl.locationcode
where sih.ordate between cast(getdate()-90 as date) and cast(getdate()-1 as date)
group by sl.item_no,sl.locationcode

Aucun commentaire:

Enregistrer un commentaire