Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is what you can do, currently making the assumption that the StatusId is in the tblMaintenanceTicket table.</p> <p>Visual Basic:</p> <pre><code>Module Module1 Sub Main() Dim rand As New Random Dim list As New List(Of tblMaintenanceTicket) For count = 1 To 100 Dim newTicket As New tblMaintenanceTicket newTicket.CreateDate = Now.AddDays(rand.Next(0, 365) * -1) newTicket.PriorityId = rand.Next(1, 6) newTicket.StatusId = 1 list.Add(newTicket) Next Dim results = From ticket In list _ Where ticket.StatusId = 1 And ticket.CreateDate.Year = Now.Year _ Group ticket By ticket.CreateDate.Month Into Group _ Select New TicketResults With { _ .Month = Month, .Critical = Group.Count(Function(t) t.PriorityId = 1), .High = Group.Count(Function(t) t.PriorityId = 2), .Normal = Group.Count(Function(t) t.PriorityId = 3), .Low = Group.Count(Function(t) t.PriorityId = 4), .NotReady = Group.Count(Function(t) t.PriorityId = 5) } End Sub Public Class tblMaintenanceTicket Public CreateDate As Date Public PriorityId As Integer Public StatusId As Integer End Class Public Class TicketResults Public Month As Integer Public Critical As Integer Public High As Integer Public Normal As Integer Public Low As Integer Public NotReady As Integer End Class End Module </code></pre> <p>C#:</p> <pre><code> class Program { static void Main(string[] args) { //Generate some random data var list = new List&lt;tblMaintenanceTicket&gt;(); var rand = new Random(); for (var count = 0; count &lt; 100; ++count) { var newTicket = new tblMaintenanceTicket(); newTicket.CreateDate = DateTime.Now.AddDays(rand.Next(0, 365)* -1); newTicket.PriorityId = rand.Next(1, 6); newTicket.StatusId = 1; list.Add(newTicket); } var results = from ticket in list where ticket.StatusId == 1 &amp;&amp; ticket.CreateDate.Year == DateTime.UtcNow.Year group ticket by ticket.CreateDate.Month into months select new TicketResults { Month = months.Key, Critical = months.Count(m =&gt; m.PriorityId == 1), High = months.Count(m =&gt; m.PriorityId == 2), Normal = months.Count(m =&gt; m.PriorityId == 3), Low = months.Count(m =&gt; m.PriorityId == 4), NotReady = months.Count(m =&gt; m.PriorityId == 5) }; System.Diagnostics.Debugger.Break(); } } public class TicketResults { public int Month { get; set; } public int Critical { get; set; } public int High { get; set; } public int Normal { get; set; } public int Low { get; set; } public int NotReady { get; set; } } public class tblMaintenanceTicket { public DateTime CreateDate { get; set; } public int PriorityId { get; set; } public int StatusId { get; set; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload