I would like to do a cross join but only retain pairs of records that are within 7 days of each other. My code below retains pairs with exactly the same date. How can it be modified to allow dates within 7 days? I am using SQL Server 2008.
SELECT
t1.[id] AS [A_id],
t2.[id] AS [B_id],
t1.[date] AS [A_date],
t2.[date] AS [B_date],
t1.[item] AS [A_item],
t2.[item] AS [B_item],
INTO [records_crossed]
FROM [records] t1
CROSS JOIN [records] t2
WHERE
t1.[date]=t2.[date]
ORDER BY t1.[id],t2.[id]