Detail sqlserver (2008) Good night, I have the following problem. I tried searching all day and found nothing. -I need to find elements in a same table that have the same date (day, time ...) and a time distance of at most 40 seconds from one to the other.
Example:
ID --- data
1 09-11-2018 19:01:10
2 09-11-2018 19:01:30
3 09-11-2018 19:01:40
----------------------------------------
4 09-11-2018 19:02:00 <--exemplo de dado que nao deveria entrar
>
I tried the following way: but without success, in the result some data is repeated and others do not match what was expected.
select *
from TABELA t join
TABELA tnext
on
datepart(DAY, t.Data) = datepart(DAY, tnext.Data) and
datepart(HOUR, t.Data) = datepart(HOUR, tnext.Data) and
datepart(minute, t.Data) = datepart(minute, tnext.Data) and
datediff(second, t.Data, tnext.Data) < 40