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
Not sure whether
Table1is actually needed here. I understand,Table2contains all the necessary information to generate the result table.I assume here that
Table1.Actual_Intimecorresponds toMIN(CAST(Table2.Date + ' ' + Table2.Time AS datetime)), andTable1.Actual_OuttimetoMAX(...), which seems to agree with the description given.