Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How can I select consecutive date from to

$
0
0

Hi guys, I got a huge table with some missing data that I need to send for a department investigation. What I need to retrieves is a series of consecutive dates or one date. I can explain better with this sample:

create table forum ( flyins int, setdate datetime2)
insert into forum values (1,'01-01-2014'),(1,'02-01-2014'), (1,'03-01-2014'), (1,'04-01-2014'), (1,'05-01-2014'),
(2,'01-01-2014'), (2,'02-01-2014'), (2,'06-01-2014'), (2,'10-01-2014'), (2,'11-01-2014'), (2,'12-01-2014'),
(3,'01-01-2014'), (3,'07-01-2014')

I need to retrieve data as:

1 01-01-2014 / 05-01-2014

2 01-01-2014 / 02-01-2014

2 06-01-2014/ 06-01-2014 

2 10-01-2014/12-01-2014

3 01-01-2014/01-01-2014

3 07-01-2014/07-01-2014

Pratically I need a from to without gap. Consecutive dates without any hole in the middle...

Thanks


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>