-1
Detail sqlserver(2008) Good evening, I have the following problem. I tried to search all day and found nothing. -I need to search for elements in the same table that have the same date (day, time ...) and a distance of time 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
NOTE: I want the query to search the data, with this distance of time according to the table without informing given any other than the seconds.
I tried it as follows: but without success, in the result some data is repeated and others do not match the 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
LAG()
+DATEDIFF(Second,..)
– Ilyes