Sooooo ... I started down a path here, and I feel like there is a simple solution looking me in the face, but I'm missing it:
INSERT INTO #topspeed
select TOP 50
*
from surround a
WHERE NOT EXISTS (SELECT
1
FROM #topspeed t
WHERE a.unid = t.unid
AND a.realtime BETWEEN DATEADD(MI, -10, t.realtime)
AND DATEADD(MI, 10, t.realtime)
)
AND a.back1 <> 0
AND a.back2 <> 0
order by a.speed DESC
The only problem is, INSERT INTO when used in conjunction with SELECT inserts all rows at once, therefore the WHERE NOT EXISTS is always true ... is there a way to do this one row at a time?