I've been working at this for a while. I was wondering how I could get this table:
id open_dt ops_hrs
1 10/31/2011 7:00AM - 5:30PM
2 11/1/2011 7:00AM - 5:00PM
3 11/2/2011 7:00AM - 5:00PM
4 11/3/2011 7:00AM - 5:00PM
5 11/6/2011 7:00AM - 7:00PM
6 11/8/2011 7:00AM - 5:00PM
to look like this table:
max_date min_date ops_hrs
10/31/2011 10/31/2011 7:00AM - 5:30PM
11/1/2011 11/3/2011 7:00AM - 5:00PM
11/6/2011 11/6/2011 7:00AM - 7:00PM
11/8/2011 11/8/2011 7:00AM - 5:00PM
I tried using a cursor but it is not necessary. Also, it has to be grouped. As soon as consecutive days break a new grouping occurs. Any help would be appreciated.
This query will generate the above sample data
;
WITH pdog (id, open_dt,ops_hrs) AS
(
SELECT 1, CAST('10/31/2011' AS datetime), '7:00AM - 5:30PM'
UNION ALL SELECT 2, CAST('11/1/2011' AS datetime),'7:00AM - 5:00PM'
UNION ALL SELECT 3, CAST('11/2/2011' AS datetime),'7:00AM - 5:00PM'
UNION ALL SELECT 4, CAST('11/3/2011' AS datetime),'7:00AM - 5:00PM'
UNION ALL SELECT 5, CAST('11/6/2011' AS datetime),'7:00AM - 7:00PM'
UNION ALL SELECT 6, CAST('11/8/2011' AS datetime),'7:00AM - 5:00PM'
)
SELECT * FROM pdog
11/4/2011 7:00AM - 6:00PM
? – Hooke