Reputation: 47
So I need to pull back data that is after 1st jan 2017 but NOT between Oct 2016 and 31st dec 2016
This is my current code:
SELECT [SequenceID]
,[AppointmentDate]
FROM dbo].[AmsAppointment]
where AppointmentDate >= Convert(datetime, '2017-01-01' ) and AppointmentDate <= Convert(datetime, '2016-10-01' )
I know the code is wrong so please help me.
Upvotes: 1
Views: 194
Reputation: 16377
You can do this a number of ways, but I think a not between
would work best:
SELECT [SequenceID], [AppointmentDate]
FROM [dbo].[AmsAppointment]
where
AppointmentDate >= '2017-01-01' and
AppointmentDate not between '2016-10-01' and '2017-12-31'
And maybe your example just that, but in your scenario, since the ranges overlap, this really translates to:
AppointmentDate >= '2017-12-31'
Upvotes: 1