I have a table with an audit log:
BugId Timestamp Status
1 2010-06-24 10:00:00 open
2 2010-06-24 11:00:00 open
1 2010-06-25 12:00:00 closed
2 2010-06-26 13:00:00 closed
I want a running total of open and closed bugs like:
Timestamp # Status
2010-06-25 00:00:00 2 open
2010-06-26 00:00:00 1 open
2010-06-26 00:00:00 1 closed
2010-06-27 00:00:00 2 closed
How may I do this query (or similar) in Microsoft SQL Server 2000?
The output is intended to be used to feed a time series chart so I do not care if there are rows with 0 output since I will probably only select a timespan like the last month.
I think the output actually matches the sample data: on the 25th (12am), there are two open bugs. On the 26th, there is one open bug and one closed. And by the 27th, all bugs are closed.
It isn’t clear how the main dates should be created. For my example, I pre-loaded the dates that I knew to be right but this could be accomplished in a variety of ways depending on the requirements of the user.
Anyway, the code is below. This should work for instances where a bug is opened and closed multiple times on the same day. It operates under the assumption that a bug cannot be opened and closed at the same time.
Results: