Here is the sample code...
CREATE TABLE #Time1
(
id INT,
City VARCHAR(10),
Atime_Source DATETIME
)
INSERT INTO #Time1
( id,City, Atime_Source )
SELECT 1,'Chicago','2017-04-10 04:28:10.000'
CREATE TABLE #Time2
(
ID INT,
City VARCHAR(20),
StartDate DATETIME,
EndDate datetime
)
INSERT INTO #Time2
( ID,City, StartDate, EndDate )
SELECT '4','Chicago','1900-01-01 04:00:00.000','1900-01-01 06:00:00.000'
SELECT * FROM #Time1
SELECT * FROM #Time2
SELECT
T1.id
,T2.ID
,T1.Atime_Source
,T2.StartDate
,T2.EndDate
FROM #Time1 T1
INNER JOIN #Time2 T2 ON T2.City = T1.City
AND DATEADD(minute, DATEDIFF(minute, DATEDIFF(day, 0, T1.Atime_Source), T1.Atime_Source), 0) BETWEEN T2.StartDate AND T2.EndDate
For some reason in original data (Can't paste here, to big" sometimes working and sometimes don't when I used the time to check in BETWEEN function.
Please any advise would be great appreciate.
Thank You.