Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3876300
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:21:57+00:00 2026-05-19T22:21:57+00:00

We have Incidents in our system with Start Time and Finish Time and project

  • 0

We have Incidents in our system with Start Time and Finish Time and project name (and other info) .
We would like to have report: How many Incidents has ‘open’ status per month per project.
Open status mean: Not finished.

If incident is created in December 2009 and closed in March 2010, then it should be included in December 2009, January and February of 2010.

Needed structure should be like this:

Project   Year    Month     Count
-------  ------  -------   -------
Test       2009   December   2
Test       2010   January     10
Test       2010   February    12
....
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:21:58+00:00Added an answer on May 19, 2026 at 10:21 pm

    In SQL Server:

    SELECT
      Project,
      Year = YEAR(TimeWhenStillOpen),
      Month = DATENAME(month, MONTH(TimeWhenStillOpen)),
      Count = COUNT(*)
    FROM (
      SELECT
        i.Project,
        i.Incident,
        TimeWhenStillOpen = DATEADD(month, v.number, i.StartTime)
      FROM (
        SELECT
          Project,
          Incident,
          StartTime,
          FinishTime = ISNULL(FinishTime, GETDATE()),
          MonthDiff = DATEDIFF(month, StartTime, ISNULL(FinishTime, GETDATE()))
        FROM Incidents
      ) i
        INNER JOIN master..spt_values v ON v.type = 'P'
          AND v.number BETWEEN 0 AND MonthDiff - 1
    ) s
    GROUP BY Project, YEAR(TimeWhenStillOpen), MONTH(TimeWhenStillOpen)
    ORDER BY Project, YEAR(TimeWhenStillOpen), MONTH(TimeWhenStillOpen)
    

    Briefly, how it works:

    • The most inner subselect, that works directly on the Incidents table, simply kind of ‘normalises’ the table (replaces NULL finish times with the current time) and adds a month difference column, MonthDiff. If there can be no NULLs in your case, just remove the ISNULL expression accordingly.

    • The outer subselect uses MonthDiff to break up the time range into a series of timestamps corresponding to the months where the incident was still open, i.e. the FinishTime month is not included. A system table called master..spt_values is also employed there as a ready-made numbers table.

    • Lastly, the main select is only left with the task of grouping the data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables, incidents , incident_properties and property_types . What I would like
I have two tables set up in a many-to-many relationship: Incidents and Users. When
I have the following Route defined in Global.asax: routes.MapRoute( IncidentActionWithId, // Route name Incidents/{companyId}/{action}/{id},
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have deployed numerous report parts which reference the same view however one of them
We use MVC controllers that access System.File.IO in our application and they work fine
I have a stored procedure as follows: CREATE PROC [dbo].[Incidents] (@SiteName varchar(200)) AS SELECT
I have an array with incidents that has happened, that are written in free
Senerio We have a C# .Net Web Application that records incidents. An external database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.