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 8803491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:21:14+00:00 2026-06-14T01:21:14+00:00

I am running into this error. I see that the reason is because the

  • 0

I am running into this error. I see that the reason is because the average returned at times is 0.00 which from a data stand point is accurate. This SQL query works fine, but that is because it puts in 0.00 automatically.

LINQ complains and so I tried using DefaultIfEmpty() but it says it is expecting my ViewModel.

Dim ticketCounts = From t In queue _
   Where _
    (t.StatusId = 2) And _
    (t.CloseDate.Year = Convert.ToDateTime(DateTime.Now).Year) And _
    (t.ResolutionDays > 0)
   Group t By _
    Column1 = CType(t.CloseDate.Month, Integer), _
    Column2 = CType(t.CloseDate.ToString("MMMM"), String) _
    Into g = Group _
   Order By Column1 _
   Select _
    Id = Column1, _
    Month = Column2, _
    Critical = g.Where(Function(t) t.PriorityId = 1).DefaultIfEmpty().Average(Function(t) t.ResolutionDays), _
    High = g.Where(Function(t) t.PriorityId = 2).DefaultIfEmpty().Average(Function(t) t.ResolutionDays), _
    Normal = g.Where(Function(t) t.PriorityId = 3).DefaultIfEmpty().Average(Function(t) t.ResolutionDays), _
    Low = g.Where(Function(t) t.PriorityId = 4).DefaultIfEmpty().Average(Function(t) t.ResolutionDays), _
    Total = g.Where(Function(t) t.Id <> Nothing).DefaultIfEmpty().Average(Function(t) t.ResolutionDays)

UPDATED!
This is the SQL query doing the same thing I need VB to do.

SELECT
    DATENAME(MONTH,t.CloseDate) AS 'Month',
    AVG(CASE WHEN (t.PriorityId = 1) THEN CAST(t.ResolutionDays AS Decimal(18, 2)) ELSE 0 END) AS 'Critical',
    AVG(CASE WHEN (t.PriorityId = 2) THEN CAST(t.ResolutionDays AS Decimal(18, 2)) ELSE 0 END) AS 'High',
    AVG(CASE WHEN (t.PriorityId = 3) THEN CAST(t.ResolutionDays AS Decimal(18, 2)) ELSE 0 END) AS 'Normal',
    AVG(CASE WHEN (t.PriorityId = 4) THEN CAST(t.ResolutionDays AS Decimal(18, 2)) ELSE 0 END) AS 'Low',
    AVG(CAST(t.ResolutionDays AS Decimal(18, 2))) AS 'Monthly Average'
FROM
    tblMaintenanceTicket t
WHERE
    t.StatusId = 2
    AND YEAR(t.CloseDate) = year(getdate())
GROUP BY 
    MONTH(t.CloseDate),
    DATENAME(MONTH,t.CloseDate)
ORDER BY
    MONTH(t.CloseDate)
  • 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-06-14T01:21:15+00:00Added an answer on June 14, 2026 at 1:21 am

    The problem is that all of the scalar LINQ methods (Average, Max, etc …) throw an exception if the input IEnumerable(Of T) doesn’t have any elements. It looks like the g.Where calls are resulting in an empty collection resulting in the exception.

    What you may want to do is write a method which handles the empty case and returns a default value.

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

Sidebar

Related Questions

After changing the import as a from-import i'm running into this error: from datetime
I keep running into this error MemCacheError (Broken pipe): Broken pipe on my Rails
I am building a XML RSS for my page. And running into this error:
I'm running into this problem when trying to call a SOAP Web Service from
I am calling a function that returns an array, but I'm running into this
I keep running into this design problem, and I'm not happy with my solution
I remember running into this problem when I started using OpenGL in OS X.
So I am running into this problem. I am trying to use $.get() to
I'm currently using Entity Framework and am running into this issue: The relationship between
Following this tutorial and running into trouble. [TestMethod] [ExpectedException(typeof(Exception))] public void VerifyPropertyNameMethod_NonExistentPropertyString_ThrowsException() { var

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.