microsoft / microsoft/sql-server-samples
Negative value for TotalCostOnDate that for specific date on --input will calculate the total cost of the inventory in the warehouse
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 11.2k
- Forks
- 9.1k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 14
Description
CREATE OR ALTER PROCEDURE warehouse.TotalCostOnSpecificDate (@Date date)
AS
BEGIN
--declare @date date = '2013.04.01'
DECLARE @TotalInvertory dec (18,2)
DECLARE @TotalChange dec (18,2)
select @TotalChange = sum(it.Quantity* ih.LastCostPrice)
from Warehouse.StockItems i
INNER JOIN Warehouse.StockItemTransactions it ON it.StockItemID=i.StockItemID
inner join Warehouse.StockItemHoldings ih on ih.StockItemID = i.StockItemID
where it.TransactionOccurredWhen > @Date
select @TotalInvertory = sum(ih.QuantityOnHand* ih.LastCostPrice)
from Warehouse.StockItemHoldings ih
inner join Warehouse.StockItems si on si.StockItemID = ih.StockItemID
select @TotalInvertory - isnull(@TotalChange,0) as TotalCostOnDate
end
exec warehouse.TotalCostOnSpecificDate @Date ='2016-04-21'
exec warehouse.TotalCostOnSpecificDate @Date ='2015-01-01'
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the warehouse.TotalCostOnSpecificDate procedure shown in the issue and run it for the supplied dates against the relevant Warehouse tables. Trace the date filter and cost calculation, then verify that the returned TotalCostOnDate matches the expected inventory cost for those dates.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100