Hi,
I have two tables that I'm looking to reference between; one table holds 2000+ rows of datetimes with ID's and the second table holds just 400 -/+ datetimes.
I need to find all the datetime (dt_tbl1) in table 1 that are round about the same time as those in table 2, (table 2 is my reference point) producing a list of ID's from table 1 that are around the datetime (dt_tbl2) of table 2.
Basically finding the 400 -/+ ID's in table 1, also table 1 is 2 - 10 seconds behind table 2.
The column type IS datetime, not float, varchar or alike etc.
Hope you follow me so far.
Here's the query ;
SELECT * FROM @table2 as tbl2
inner join @table1 as tbl1 on tbl1.dt_tbl1 = tbl2.dt_tbl2
However I know the
tbl1.dt_tbl1 = tbl2.dt_tbl2
part will just look for exact matches, but I need it to find datestimes (dt_tblx) give or take 2 - 10 seconds.
Anyone know how I can elaborate the query to do this?
I'm guessing it would be something like
DATEDIFF(SS,tbl2.dt_tbl2,tbl1_dt_tbl1) <= 4
Thanks,
James