Hi @dani shamir
Suppose you have a calendar table say #Date, then you can try the query below:
CREATE TABLE #Bug(bug_id int,opened_date DATE,closed_date DATE)
INSERT INTO #Bug VALUES(1,'01/01/2015','1/04/2015'),(2 ,'01/02/2015', null),(3 ,'01/03/2015', '1/4/2015')
SELECT D.TheDate,COUNT(B.bug_id) AS Num_of_OpenedBugs
FROM #Date D JOIN #Bug B ON D.TheDate>=B.opened_date AND D.TheDate<(CASE WHEN B.closed_date IS NULL THEN GETDATE() ELSE B.closed_date END)
--WHERE D.TheDate BETWEEN @STARTDATE AND @ENDDATE
GROUP BY TheDate
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.