0

I have two tables, table1 and table2.

And I join them by comparing a couple of columns and one of them is a Date column.

select *
from table1 t1 
INNER JOIN table2 t2 ON t1.HaloDate = t2.HaloDate

My question is I found that the join fails for comparison of 2 dates below:

'2011-07-23 14:01:32.113' and '2011-07-23 14:01:32.114'

is it possible to write this join by ignoring the miliseconds or by introducing a range like 5 milisecons as a tolerance range?

Thanks

4

2 に答える 2

4

DATEDIFF 関数を使用して、必要な範囲を配置します。次に例を示します。

ABS(DATEDIFF(second, DateField1, DateField2)) < 5

日付値の差が 5 秒未満であることを意味します。

ミリ秒から年までの時間範囲に任意のタグを使用できます

于 2011-12-22T14:03:45.167 に答える
4

はい:

select *
from table1 t1 
INNER JOIN table2 t2 
ON t1.HaloDate between dateadd(ms,-5,t2.HaloDate) and dateadd(ms,5,t2.HaloDate) 
于 2011-12-22T14:03:54.700 に答える