Example
I want to calculate the worktime between 09:00:00 to 18:00:00,
09:00:00 - Normal_Intime
18:00:00 - Normal_Outtime
Suppose
1) Intime is 10:00:00, Outtime is 17:00:00 It should give the output as 07:00:00
2) Intime is 08:00:00. Outtime is 19:00:00 It should give the output as 09:00:00
above output should compare with Normal_Intime, Normal_Outtime .
Means Normal_Intime is 09:00:00 only and Normal_Output is 18:00:00 only, so Intime should not > 09:00:00 and Outtime < 18:00:00.
Query
select Intime, Outtime, CONVERT(char(8), CASE WHEN OutTime > Normal_Outtime THEN cast(Normal_Outtime AS datetime) ELSE cast(OutTime AS datetime) END - CASE WHEN InTime > Normal_Intime THEN cast(InTime AS datetime) ELSE cast(Normal_Intime AS datetime) END, 8) AS WorkTime from table
Output
Intime Outtime Worktime
15:37:48 22:08:15 02:22:12
07:33:34 07:59:13 22:59:13
the Second Row giving wrong output It should give only 00:25:39
If both in and out time is smaller than NormalInTime and both in and out time is greater than NormalOutTime. How to make a condtion for this
How to make a query for this conditon.
Need Query Help.