-- SQL SERVER 2008 R2
the problem rows are (look attached jpg post#2)
emp_code,trans_date,timein,timeout,dateout2
'182176','2020-08-24','20:20:09','13:51:20','2020-08-25'
'182176','2020-08-25','08:57:14','13:51:20','2020-08-25'
because timeout + dateout2 is not unique.
this means that there is a missing timeout
that is the employee left out without marking his timeout in front of attendance machine.
What I want
update (I want update not select) column remarks in table @t
frist problem row with 'out missing'
2nd problem row with 'work hours reset'
The following script will create table and insert sample data
declare @t table (emp_code varchar(6), trans_date datetime, timein varchar(8), timeout varchar(8), dateout2 datetime, remarks varchar(15))
insert @t (emp_code , trans_date , timein , timeout , dateout2, remarks)
select '182176','2020-08-20','20:00:59','05:43:24','2020-08-21','' union all
select '182176','2020-08-21','20:14:07','05:30:31','2020-08-22','' union all
select '182176','2020-08-22','20:35:03','05:00:00','2020-08-23','' union all
select '182176','2020-08-24','20:20:09','13:51:20','2020-08-25','problem' union all
select '182176','2020-08-25','08:57:14','13:51:20','2020-08-25','problem' union all
select '182176','2020-08-26','09:29:53','19:00:52','2020-08-26','' union all
select '182176','2020-08-27','09:41:45','13:00:00','2020-08-27',''
select emp_code, trans_date , timein , timeout , dateout2, remarks from @t
after update the result would be
emp_code , trans_date , timein , timeout , dateout2, remarks
182176,2020-08-24,20:20:09,13:51:20,2020-08-25,out missing
182176,2020-08-25,08:57:14,13:51:20,2020-08-25, work hours reset