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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:36:19+00:00 2026-05-11T16:36:19+00:00

Can some kind soul please lend me the Linq To SQL query for the

  • 0

Can some kind soul please lend me the Linq To SQL query for the following T-SQL Query

SELECT e.EmployeeName, MIN(a.SignInTime), MAX(a.SignOutTime)
FROM Employee e
LEFT OUTER JOIN Attendance a ON e.Id = a.EmployeeId AND CAST (CONVERT (varchar, a.SignInTime, 106) AS DATETIME) = '28 APR 2009'
GROUP BY e.EmployeeName

The database schema i have is as follows

Employee: {Id: int identity PK, EmployeeName: varchar(200) NOT NULL}
Attendance: {Id: int identity PK, EmployeeId: int FK(Employee(Id)) NOT NULL, SignInTime: DateTime, SignOutTime: DateTime}

NOTE: The Convert gimmick is only used to chop off the time portion in the SignInTime for comparision

  • 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-11T16:36:19+00:00Added an answer on May 11, 2026 at 4:36 pm

    This is definitely a challenge. It’s ugly, but It does the trick. It returns exactly what you are looking for. In the case of employees without attendance, you get back the name with null times.

    var selectedDate = new DateTime(2009,4,28);
    var query = from e in db.Employees
        join a in db.Attendances on e.Id equals a.EmployeeId into Temp          
        from t in Temp.DefaultIfEmpty()
        where t.SignInTime == null || (t.SignInTime >= selectedDate && t.SignInTime < selectedDate.AddDays(1))
        group t by e.EmployeeName into grouped          
        select new
        {
           Employee = grouped.Key,
           FirstSignInTime = grouped.Min(a => a.SignInTime),
           LastSignOutTime = grouped.Max(a => a.SignOutTime)
        };
    

    This is the SQL that is emitted by that expression:

    DECLARE @p0 DateTime = '2009-04-27 00:00:00.000'
    DECLARE @p1 DateTime = '2009-04-28 00:00:00.000'
    
    SELECT MIN([t1].[SignInTime]) AS [FirstSignInTime], MAX([t1].[SignOutTime]) AS [LastSignOutTime], [t0].[EmployeeName] AS [Employee]
    FROM [Employee] AS [t0]
    LEFT OUTER JOIN [Attendance] AS [t1] ON [t0].[Id] = [t1].[EmployeeId]
    WHERE ([t1].[SignInTime] IS NULL) OR (([t1].[SignInTime] >= @p0) AND ([t1].[SignInTime] < @p1))
    GROUP BY [t0].[EmployeeName]
    

    This is very close to your original SQL. I added where “t.SignInTime == null” so that it returns employees with attendance, but you can remove that if that’s not what you want.

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

Sidebar

Related Questions

...just like packages do. I use Emacs (maybe, it can offer some kind of
Can I set some kind of global variable for the length of a single
I'm looking for some kind of text-parser for ASP.NET that can make HTML from
Do you need to use some kind of provider? Can you setup your own
Say you're coding some kind of web application. Something where people can contribute content,
I'm wondering if there's some kind of criteria that can be used to determine
On Linux/NPTL , threads are created as some kind of process. I can see
Ho can i bypass this restriction? I know i can use some kind of
Can I add some kind of custom attributes in XAML ?
Can some one specify the windows API, one need to use in order to

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.