Try the following:
Sample data:
use tempdb
create table temp(
[date] datetime,
type varchar(100),
[log] varchar(100)
)
insert into temp values
('11/20/2014 09:05', 'System', 'Order Added'),
('11/20/2014 09:18', 'Mark', 'Invoice Printed'),
('11/20/2014 10:00', 'System', 'Failed to notify Customer'),
('11/20/2014 10:05', 'System', 'Failed to notify Customer'),
('11/20/2014 10:10', 'System', 'Failed to notify Customer'),
('11/20/2014 10:15', 'System', 'Failed to notify Customer'),
('11/20/2014 10:20', 'System', 'Failed to notify Customer'),
('11/20/2014 12:05', 'System', 'Order Completed');
Solution using ROW_NUMBER():
with cte as(
select
*,
rn = row_number() over(partition by log order by [date]),
cc = count(*) over(partition by log)
from temp
where
log = 'Failed to notify Customer'
)
delete
from cte
where
rn > 1 and rn < cc
select * from temp
drop table temp
source
share