CHARINDEX(' ', REVERSE(RTRIM(sc.ChangeDescription))) - 1)) as orderno,
case when (sc.TransactionType='PURCHASE') then UnitPriceAddition
when (sc.TransactionType ='VENDOR RETURN') then UnitPriceSubtraction
end as UnitPurchasePrice,
case when (sc.TransactionType='PURCHASE') then AdditionQty
when (sc.TransactionType='VENDOR RETURN') then SubtractionQty
end as PurchaseQty,
case when (sc.TransactionType='PURCHASE') then ExtendedAdditionPrice
when (sc.TransactionType='VENDOR RETURN') then ExtendedSubtractionPrice
end as ExtendedCostPrice
FROM PSRentalworksDW.dbo.SalesInventoryChange sc
WHERE (sc.TransactionType ='PURCHASE' OR sc.TransactionType='VENDOR RETURN')
AND sc.TransactionDate >= '2013-01-01';
[Sales]:
CONCATENATE (SalesAndPurchases)
Load
warehouse,
masterid,
//masterno,
//ICodeDescription,
Date(TransactionDate, 'YYYY-MM-DD') as TransactionDate,
TransactionType,
orderno,
UnitSalePrice,
SalesQty,
ExtendedSalesPrice;
SQL SELECT
es.warehouse,
RTRIM(es.masterid) masterid,
//es.masterno,
//es.description as ICodeDescription,
es.transdate as TransactionDate,
es.transtype as TransactionType,
es.orderno,
es.price as UnitSalePrice,
es.qtyordered as SalesQty,
es.priceextended as ExtendedSalesPrice
FROM RWReports.dbo.ExpendableSales es;
Now In order to calculate Average Inventory Value for the last 12 months, I need to use case statements or something similar
where if the Purchase Date is within the last 12 months, it will use that as the Cost price for the item and then use that date for the Daily Inventory to get the value that date. How would I go about doing this?