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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:40:05+00:00 2026-05-25T16:40:05+00:00

I have a query for sql server that returns this table below. The query

  • 0

I have a query for sql server that returns this “table” below. The query uses some joins to link the data together. What I’m trying to do is add up each interviewers logged in time and in addition turning NULL into the time at this moment.

INTERVIEWER NUM_COMPLETES   projectId   loginDateTime   logoutDateTime
002                2    43407      2011-09-20 22:59:15.193  NULL
004                1    43407      2011-09-20 23:06:32.287  NULL
007                1    43407      2011-09-20 23:02:30.930  NULL
007                1    43407   2011-09-20 00:37:01.213 2011-09-20 01:15:00.197
010                3    43407      2011-09-20 23:04:46.547  NULL
013                1    43407   2011-09-20 00:36:16.923 2011-09-20 01:14:59.440
029                3    43407   2011-09-20 22:58:55.083 2011-09-20 23:30:56.987
029                3    43407   2011-09-20 23:31:05.243 2011-09-21 00:02:27.560
029                3    43407     2011-09-21 00:02:55.527   NULL
032                1    43407     2011-09-20 22:59:19.590   NULL
036                1    43407     2011-09-20 23:02:33.497   NULL
041                1    43407     2011-09-20 22:59:55.020   NULL

Should turn into

INTERVIEWER NUM_COMPLETES   projectId   TotalTime
002                2      43407            8
004                1      43407            10
007                1      43407            4
008                1      43407            7

It’s like a date diff that is summed up per interviewer.

Here is a sample + sanitized tsql statement that I am using


SELECT tbl1.INTERVIEWER, tbl1.NUM_COMPLETES, tbl2.projectId, tbl2.loginDateTime, tbl2.logoutDateTime
FROM 
(
SELECT k_Id, FirstName AS INTERVIEWER, COUNT(result) AS NUM_COMPLETES
FROM db1_table, db2_table
WHERE k_Id=Interviewer
GROUP BY k_Id, FirstName, result
) AS tbl1
INNER JOIN
(
SELECT projectId, loginDateTime, logoutDateTime, userId
FROM session_tbl
WHERE loginDateTime >= '2011-09-20 0:0:0.0' AND projectId = '43407'
) AS tbl2
ON tbl1.k_Id=tbl2.userId
ORDER BY INTERVIEWER

Thank you for any help — I’ve been struggling with this the past couple of days!

  • 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-25T16:40:06+00:00Added an answer on May 25, 2026 at 4:40 pm

    You should be able to use a standard GROUP BY to do this.

    select
        userId, 
        projectId, 
        sum(datediff(hour, loginDateTime, isnull(logoutDateTime, getdate()))) as totalHours
    
    from session_tbl
    
    group by userId, projectId
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Microsoft SQL Server 2008 query that returns data from three tables
Possible Duplicate: SQL Server Database query help Hi, I have a problem that I
We're using SQL Server 2000 Query Analyser, and one issue we have is that
I have this query in sql server 2000: select pwdencrypt('AAAA') which outputs an encrypted
i have a general question about how sql server evaluates the joins.The query is
I have a SQL Server DB containing a registrations table that I need to
I have a SQL Server query that I need to convert to MySQL. I've
I have a SQL Server 2005 database that stores data for multiple users. Each
Background: I'm using SQL Server Management Studio 2008 and I have a query window
How to use conditional select query in SQL Server ? I have a column

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.