0

Suppose that I hava a table T, with

Create Table T (id int, date Datetime);
Insert Into T (id,date) Values 
(1,'2012-12-11'),(2,'2012-12-12'),
(3,'2012-12-13'),(4,'2012-12-15'),
(5,'2012-12-17'),(6,'2012-12-18'),(7,'2012-12-19');

And suppose the given range of date are form 2012-12-09 to 2012-12-16, I want to get the range of date in T, such that is not in the range. I try this code:

Select date From T where '2012-12-09'<= date AND date <= '2012-12-16';

It output all the data in the range, but this is NOT I hope to get, what I need is that to return something like:

start       end
2012-12-09  2012-12-10
2012-12-14  2012-12-14
2012-12-16  2012-12-16

That is the range not in the given one. (See the comment below), That is the range not in T (but in the given one, i.e, '2012-12-09'-'2012-12-16').

As a test, you can try it here: http://sqlfiddle.com/#!2/e55ba/1

van abel
  • 181
  • 10

1 Answers1

0

Just try this where condition in your query then you will get all the result that are not in range. where '2012-12-09'<= date AND date >= '2012-12-16'

Adal Singh
  • 106
  • 2