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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:58:00+00:00 2026-05-16T21:58:00+00:00

When two tables are given Employee Table EmpID Name 1 Jon 2 Smith 3

  • 0

When two tables are given

Employee Table

EmpID  Name
1      Jon   
2      Smith  
3      Dana 
4      Nancy

Lab Table

EmpID   StartTime   EndTime    Date            LabID
1       10:00 AM    12:15 PM   01/JAN/2000     Lab I 
1       11:00 AM    14:15 PM   01/JAN/2000     Lab II 
1       16:30 PM    18:30 PM   01/JAN/2000     Lab I

2      10:00 AM    12:10 PM    01/JAN/2000     Lab I

From the given details ,I have to find out the overlapping hours,and non overlapping hours of each employee on each date. (StartTime and EndTime are of type varchar).

The expected output is 
-------------------------------------------------------------------------------
EmpID| Name|  Overlapping                 | Non-Overlapping      |    Date 
              Period                        Period  
-------------------------------------------------------------------------------
1      Jon | 10:00 AM  to 12:15 PM       |16:30 PM to   18:30 PM | 01/JAN/2000   
           |  AND                        |                       | 
           |  11:00 AM  to 14:15 PM      |                       |
           |  AND ...(If any)            |                       | 
--------------------------------------------------------------------------------

2    Smith|      NULL                    | 10:00 AM to 12:10 PM  |01/JAN/2000
-------------------------------------------------------------------------------- 

Please help me to bring such output using TSQL(SQL Server 2005/2008).

  • 1 1 Answer
  • 1 View
  • 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-16T21:58:00+00:00Added an answer on May 16, 2026 at 9:58 pm

    First, you should probably consider using a DateTime field to store the StartTime and EndTime, and thus make calculations easier, and remove the need for the Date field.

    SELECT t1.EmpID, 
           t1.StartTime, 
           t1.EndTime,
           t2.StartTime
           t2.EndTime,
    FROM lab t1
    LEFT OUTER JOIN lab t2
       ON t2.StartTime BETWEEN t1.StartTime AND t1.EndTime
          AND t2.EmpID = t1.EmpID
    ORDER BY t1.EmpID,
             t1.StartTime,
             t2.StartTime
    

    That won’t get you the EXACT format you have listed, but it’s close. You should end up with:

    | EmpID|   Name|    Normal Period    | Overlapping Period  |
    ------------------------------------------------------------
    | 1    |   Jon | 10:00 AM | 12:15 PM | 11:00 AM | 02:15 PM |
    ------------------------------------------------------------
    | 2    | Smith | 10:00 AM | 12:10 PM | NULL     | NULL     |
    ------------------------------------------------------------
    

    Each overlapped period within a normal period would show up in a new row, but any period with no overlaps would have only one row. You could easily concatenate the fields if you wanted specifically the “xx:xx xx to xx:xx xx” format. Hope this helps you some.

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

Sidebar

Related Questions

Two tables are given PilotGroup Table Pilot Plane Jon Smith A1-Fighter Jon Smith B1-Fighter
Given two tables APPLE and ORANGE, NAME APPLES Alice 5 Bob 10 Trudy 1
given the two tables and values: Tables People- Columns: [ID]PK Name Field - Columns:
Table Schema For the two tables, the CREATE queries are given below: Table1: (file_path_key,
Given are two tables, Table A containing customerid , lastchange , internallink Table B
I have two tables, like so: table a contains: id|name stock1|fullname stock2|fullname2 stock3|fullname3 table
I have two tables one Employee and mailing Subscriptions Employee looks like this: Name
I have two tables as given below Table A Table B Table C =============
Table Schema For the two tables, the CREATE queries are given below: Table1: (file_path_key,
Problem Given the following two tables, I'd like to select all Ids for Posts

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.