尝试检查日期范围时,它不会返回值。 st_date
的{{1}}和end_date
是序列,因此它应仅返回usr_id = 1
个值,并且不应返回usr_id = 1
,因为它不是序列。如果日期范围不是按顺序排列,则不应返回任何值。
usr_id = 3
答案 0 :(得分:0)
SELECT *
FROM #temp t
INNER JOIN #temp t2 ON t.usr_id = t2.usr_id AND t.end_date = DATEADD(dd, -1, t2.st_date)
WHERE @st_dt BETWEEN t.st_date AND t.end_date
AND @end_dt BETWEEN t2.st_date AND t2.end_date