• That's an Itzik Ben-Gap "Gaps and Islands" query.  Sorry, I don't have time now to fully flesh it out, but someone should come along shortly who can.

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.