Reputation: 1715
I need to only pull records that have have a date span of 2 or more days. I have over 8K records I need to search through. What's the best way to do this please? I'm using SQL Server 2014.
In case SQL Fiddle doesn't work: (I've had issues getting it to work lately.)
create table #DD
(
Event varchar(100),
ResponseBegin date,
ResponseEnd date
)
insert into #DD
(Event, ResponseBegin, ResponseEnd)
values ('Det', '20150201', '20150202'),
('Adm', '20160201', '20160204'),
('MM', '20120201', '20120205'),
('Det', '20160201', '20160207'),
('Det', '20160201', '20160201')
Data
Desired Results
Thank you.
Upvotes: 0
Views: 72
Reputation: 140
This might work:
SELECT * FROM DD WHERE ResponseEnd <= DATEADD(day, 2, ResponseBegin)
Upvotes: 0
Reputation: 497
Try
SELECT * FROM DD WHERE
ResponseEnd <= DATEADD(day, 2, ResponseBegin)
Upvotes: 0
Reputation: 3705
You can do the following:
SELECT * FROM DD WHERE DateAdd(DAY, 2, ResponseBegin) <= ResponseEnd
Upvotes: 1