 <p>You question is a bit unclear, but I think this will point you in a productive direction. SQL is designed to perform operation on sets of rows, not to loop through processing one row at a time. The following code will correlate your data into one row for each pair of slots at each date/time. You can use a <code>CASE</code> expression, as shown, to add a column that indicates the status of the row, and you can then add a <code>WHERE</code> clause, not shown, to perform any additional filtering.</p> <pre><code>-- Sample data. declare @Samples as Table ( SampleId Int, Slot Int, EventDate Date, StartTime Time(0), EndTime Time(0), Action VarChar(10) ); insert into @Samples ( SampleId, Slot, EventDate, StartTime, EndTime, Action ) values ( 200, 1, '20150501', '00:00:00', '00:30:00', NULL ), ( 201, 2, '20150501', '00:00:00', '00:30:00', NULL ), ( 202, 1, '20150501', '00:30:00', '01:00:00', 'A' ), ( 203, 2, '20150501', '00:30:00', '01:00:00', NULL ), ( 204, 1, '20150501', '01:00:00', '01:30:00', NULL ), ( 205, 2, '20150501', '01:00:00', '01:30:00', 'A' ), ( 206, 1, '20150501', '01:30:00', '02:00:00', 'B' ), ( 207, 2, '20150501', '01:30:00', '02:00:00', 'B' ); select * from @Samples; -- Data correleated for each date/time. select Slot1.EventDate, Slot1.StartTime, Slot1.EndTime, Slot1.Action as Action1, Slot2.Action as Action2, Coalesce( Slot1.Action, Slot2.Action ) as SummaryAction, case when Slot1.Action = Slot2.Action then 'ERROR!' else 'Okay.' end as Status from @Samples as Slot1 inner join @Samples as Slot2 on Slot2.EventDate = Slot1.EventDate and Slot2.StartTime = Slot1.StartTime and Slot1.Slot = 1 and Slot2.Slot = 2; </code></pre>