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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:35:34+00:00 2026-05-19T23:35:34+00:00

Using SQL Server Table1 ID Actual_Intime Actual_Outtime 001 08:00:00 18:00:00 (HHMMSS) 002 20:00:00 06:00:00

  • 0

Using SQL Server

Table1

ID Actual_Intime Actual_Outtime

001 08:00:00 18:00:00 (HHMMSS)
002 20:00:00 06:00:00
003 05:00:00 14:00:00
004 19:30:00 03:30:00
...

…

Actual_Intime Datatype is nvarchar
Actual_Outtime Datatype is nvarchar

I need to validate the employee time like

“If outtime is less than Intime, then it should take the intime and outtime on the same day”

“if outtime is greater than intime, then it should take the intime on the same day and outtime should be the next day.

Table2

ID Date Time

001 20100102 06:00:00
001 20100102 08:00:00
001 20100102 14:00:00
001 20100102 19:00:00
002 20100102 19:00:00
002 20100102 21:00:00
002 20100103 03:00:00
002 20100103 07:00:00
...,

…

Date Datatype is nvarchar
Time Datetype is nvarchar

Date Format: yyyymmdd
Time Format: HHMMSS

I need to take the Min(time) and Max(time) from the table2 but table2 compare the actual intime and actual outtime from table1

Expected Output

ID Date Intime Outtime

001 20100102 06:00:00 19:00:00 

(Here Actual_Outtime is less than Actual_Intime from table1, so In table2 it should take the intime and outtime on the same day)

002 20100102 19:00:00 07:00:00 

(Here Actual_Outtime is greater than Actual_Intime from table1, so In table2 it should take the next day time as outtime)

How to get the Intime and Outtime compare with actual Intime and actual Outtime from Table1.

Need Query Help

  • 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-19T23:35:34+00:00Added an answer on May 19, 2026 at 11:35 pm

    Not sure whether Table1 is actually needed here. I understand, Table2 contains all the necessary information to generate the result table.

    SELECT
      ID,
      date =    CONVERT(char(8), intime,  112),
      intime =  CONVERT(char(8), intime,  108),
      outtime = CONVERT(char(8), outtime, 108)
    FROM (
      SELECT
        ID,
        intime =  MIN(dt),
        outtime = MAX(dt)
      FROM (
        SELECT
          ID,
          dt = CAST(Actual_Intime + ' ' + Actual_Outtime AS datetime)
        FROM Table2
      ) s
    ) m
    

    I assume here that Table1.Actual_Intime corresponds to MIN(CAST(Table2.Date + ' ' + Table2.Time AS datetime)), and Table1.Actual_Outtime to MAX(...), which seems to agree with the description given.

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

Sidebar

Related Questions

Using SQL Server 2000 table1 id values (datatype is nvarchar) 001 12:10 002 01:25
Using SQL Server 2000 Table1 Id date --- ---------- 001 23/01/2012 002 25/01/2012 003
Using SQL Server 2005 and VB.Net Table1 ID Name Dept 001 Raja IT 002
Using SQL Server 2000 Table PersonID Date 001 11-02-2009 002 11-02-2009 003 11-02-2009 001
Using SQL Server 2005 Database1 Table1 ID Date Status 001 23-02-2009 Worked 001 24-02-2009
Using SQL Server 2000 Table1 ID Date Value1 Value2 001 01/01/2012 100 0 001
Using SQL Server 2000 Having Two Tables Table1 Date ID 20090101 001 20090102 001
Im using SQL Server 2005. I have a table1 with 3 columns. And table2
Using MS SQL Server but porting on MySQL so I need a solution for
[using SQL Server 2005] I have a table full of users, I want 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.