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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:47:26+00:00 2026-06-08T06:47:26+00:00

I have a table the contains appointments. These appointments have different statuses (byte from

  • 0

I have a table the contains appointments. These appointments have different statuses (byte from 1 to 5) and dates; the column for the date is simply called AppointDate. I pass in a list of IDs and I want to group the result based on the status AND whether the date of the appointment is past or not.

TheIDs is a list of longs that’s passed in as the parameter. This is what I have so far:

var TheCounterInDB = (from a in MyDC.Appointments
                      where TheIDs.Contains(a.ID)
                      group a by a.AppointStatus into TheGroups
                      select new { 
                             TheStatus = TheGroups.Key,
                             TheTotalCount = TheGroups.Count(),
                             TheLateCount = ?,
                             ThePendingCount = ?
                      }).ToList();

Basically, I want TheLateCount to be the count of all the appointments where status is 1 AND the date is past and ThePendingCount to be the count where status is 1 AND the date is not past. My anonymous type is good to return the count of all the different statuses (that’s where the .Key is) but I’m wondering how to best add the date requirement into the grouping.

Thanks for your suggestions.

  • 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-08T06:47:27+00:00Added an answer on June 8, 2026 at 6:47 am
    var TheCounterInDB = (from a in MyDC.Appointments
                          where TheIDs.Contains(a.ID)
                          group a by a.AppointStatus into TheGroups
                          select new { 
                                 TheStatus = TheGroups.Key,
                                 TheTotalCount = TheGroups.Count(),
                                 TheLateCount = TheGroups.Count(x => x.AppointStatus == 1 && x.AppointDate < DateTime.Today),
                                 ThePendingCount = TheGroups.Count(x => x.AppointStatus == 1 && x.AppointDate >= DateTime.Today)
                          }).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table which contains 2 date fields. Like: id from to --- ----
I have a table contains a column with Date datatype. I want to get
I have a table on my database called 'Log'. This Log table contains ID,
I have one table which contains events and dates, and another which contains the
I have a table that includes a column for the user to select from
Intro: I have an database with table which contains column with hours, for example
I have table which contains data along with created on date. I want to
I have a table contains various columns including two DateTime column, Start and End
I have a table that contains records, with a DATETIME column. I am writing
I have a table called orders this table contains all the information we need.

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.