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

  • Home
  • SEARCH
  • 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 387713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:41:58+00:00 2026-05-12T15:41:58+00:00

Using SQL Server 2000 I want to get Table2.TimeIn Table2.TimeOut according to Table1.personid and

  • 0

Using SQL Server 2000

I want to get Table2.TimeIn Table2.TimeOut according to Table1.personid and also If Table1.Date = Table3.Date then it should take a Table3.TimeIn, Table3.TimeOut.

3 Tables

Table1

ID    Date  

001 20090503 
001 20090504 
001 20090506 
002 20090505 
002 20090506 

So on…,

Table2

ID    TimeIn TimeOut

001 08:00:00 18:00:00
002 08:00:00 21:00:00

So on…,

Table3

ID    Date  TimeIn TimeOut

001 20090504 10:00:00 22:00:00
001 20090505 17:00:00 23:00:00
002 20090505 12:00:00 21:00:00 

So on…,

Select Table1.ID, 
       Table1.Date, 
       Table2.TimeIn, 
       Table2.TimeOut 
  from Table1 
Inner Join Table2 on Table1.ID = Table2.ID 

If Table1.Date = Table3.Date then it should take Table3.TimeIn, Table3.TimeOut else Table2.TimeIn, Table2.Timeout

Expected Output

ID Date TimeIn TimeOut

001 20090503 08:00:00 18:00:00
001 20090504 10:00:00 22:00:00 
001 20090506 08:00:00 18:00:00
002 20090505 12:00:00 21:00:00
002 20090506 08:00:00 21:00:00

So on…,

How to write a query for this condition?

  • 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-12T15:41:58+00:00Added an answer on May 12, 2026 at 3:41 pm

    Employee time schedule fallback?:

    SELECT Table1.ID
        ,Table1.Date
        ,COALESCE(Table3.TimeIn, Table2.TimeIn) AS TimeIn
        ,COALESCE(Table3.TimeOut, Table2.TimeOut) AS TimeOut
    FROM Table1
    INNER JOIN Table2 -- Always have an expected schedule for an employee
        ON Table1.ID = Table2.ID
    LEFT JOIN Table3 -- May.may not have an actual schedule for an employee
        ON Table3.ID = Table1.ID
        AND Table3.Date = Table1.Date
    /*
    ORDER BY Table1.ID
        ,Table1.Date
    */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 200k
  • Answers 200k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Generics as a rule are not supported in any interop… May 12, 2026 at 7:55 pm
  • Editorial Team
    Editorial Team added an answer The IIS7 Url Rewrite Module is a native code DLL… May 12, 2026 at 7:55 pm
  • Editorial Team
    Editorial Team added an answer returns the following: &38;&65;&116;&105;&108;&100;&101;&59;&38;&112;&97;&114;&97;&59;... That's: öäü Which says your AJAX… May 12, 2026 at 7:55 pm

Related Questions

Is there any way for a DBA to peek in on the execution plan
Is it possible to grab a file using T-SQL via HTTP? I'm familiar with
I'm in a situation where I would to generate a script for a database
We are using SQL Server 2000 and have to move data across servers to
I am using Ubuntu 9.04 I have installed the following package versions: unixodbc and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.