I need to extract the values from a field from the first and last day of week. Basically I need to show a status of units at the beginning and at the end of the week. Week is determined from monday to sunday, the table I need to extract this from is as follows:
Product number Quantity Date
1 15 4/3/2017 00:00:00.0000000
1 20 4/4/2017 00:00:00.0000000
1 20 4/5/2017 00:00:00.0000000
1 20 4/6/2017 00:00:00.0000000
1 25 4/7/2017 00:00:00.0000000
1 32 4/8/2017 00:00:00.0000000
1 37 4/9/2017 00:00:00.0000000
2 5 4/3/2017 00:00:00.0000000
2 10 4/4/2017 00:00:00.0000000
2 11 4/5/2017 00:00:00.0000000
2 12 4/6/2017 00:00:00.0000000
2 14 4/7/2017 00:00:00.0000000
2 15 4/8/2017 00:00:00.0000000
2 20 4/9/2017 00:00:00.0000000
In my table, I have an entry per date (the Date field is actually datetime) showing an snapshot of the inventory for that specific date. Taking in mind that 4/3 is monday and 4/9 is sunday, I need to have the quantity for the 4/3 and the 4/9 for all my product numbers, so the results should be:
Week Product number Starting inventory Ending Inventory
From 4/3 to 4/9 1 15 37
From 4/3 to 4/9 2 5 20
I need to do this for all april and may 2017 for more than 100 product numbers through a query in sql server. Can you help me out on how to do it?
Thanks!