I have data in the format:
Date, FirstName, LastName, Unit
Jan1 , Bob , Guy , Home
Jan2 , Bob , Guy , Home
Jan3 , Bob , Guy , Home
Jan5 , Bob , Guy , Home
Jan6 , Bob , Guy , Home
Jan7 , Bob , Guy , Home
Jan8 , Bob , Guy , Offsite
Jan3 , Jane , Doe , Home
Jan4 , Jane , Doe , Home
Jan5 , Jane , Doe , Home
Jan9 , Bob , Guy , Home
Jan10, Bob , Guy , Home
Jan11, Bob , Guy , Home
Jan12, Jane , Doe , Home
Jan13, Jane , Doe , Home
Jan14, Jane , Doe , Home
and I want it in the format
DateStart, DateEnd, FirstName, LastName, Unit
Jan1 , Jan3 , Bob , Guy , Home
Jan5 , Jan7 , Bob , Guy , Home
Jan8 , Jan8 , Bob , Guy , Offsite
Jan3 , Jan5 , Jane , Doe , Home
Jan9 , Jan11 , Bob , Guy , Home
Jan12 , Jan14 , Jane , Doe , Home
Edit: Updated the data.
How can I convert the data easily?
This is a one time conversion.
Thanks for the comments/answers!
The SQL below will produce the desired output, But I'm not sure if you're not better off writing this is C#
Update This has been updated to a proper gaps and island solution. This is based on the MSDN article Islands and Gaps in Sequential Numbers by Alexander Kozak. This could be improved on by using CTE's and also the Exists could be replaced with LEFT JOINs.
It should be noted that this relies on the Dates to not have any time component. If there were a time component it would have to be removed up front.
Output
SQL Statement
Using Conrad's test data and Itzik Ben Gan's approach!