I have been working on this for a while. I was wondering how can I 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 the cursor, but this is optional. In addition, it must be grouped. As soon as the following days are interrupted, a new grouping arises. 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
source share