So I've got 2 Date Columns, start and end. What I am trying to accomplish is inventory for each day and this will be going back to the beginning of 2020 so that I have these fields:
Start Date, count of new adds that day, count of closed that day, and count of existing open from previous days. My basic data structure I derive is Start Date, End Date, Request Type (if start date = date of report and end date is null then 'New Add', if end date is not null then 'Work Closed' and if Start Date is less than date of report then 'Existing Open'. The problem is that these depend on relativity between the report date and open/close dates. I need to be able to group by a date and give the counts for each day. I tried these 2 solutions and didn't work like I had hoped for as they're slightly different than my scenario. (Count Function on Multiple Columns by Date (SQL Server) and Get count on two different date columns and group by date). When I boils down I need to do a count by each day based on the current date inventory and the existing stuff from the previous day.
My basic data structure is like this and is fake data:
+----+------------+-----------+---+
| ID | StartDate | EndDate | |
+----+------------+-----------+---+
| 1 | 1/1/2020 | NULL | |
| 2 | 12/1/2019 | 1/1/2020 | |
| 3 | 1/1/2020 | 1/3/2020 | |
| 4 | 12/17/2019 | 1/2/2020 | |
+----+------------+-----------+---+
Expected Result:
+-------------+---------+-----------------+-----------+--+--+------+
| Report Date | NewAdds | ExistingOpen | Closed | | | |
+-------------+---------+-----------------+-----------+--+--+------+
| 1/1/2020 | 2 | 1 | 1 | | | |
| 1/2/2020 | 0 | 1 | 1 | | | |
| 1/3/2020 | 0 | 1 | 1 | | | |
+-------------+---------+-----------------+-----------+--+--+------+