Skip to content

Instantly share code, notes, and snippets.

@nramsbottom
Created June 5, 2014 09:17
Show Gist options
  • Select an option

  • Save nramsbottom/7aef73df60cc0945ea90 to your computer and use it in GitHub Desktop.

Select an option

Save nramsbottom/7aef73df60cc0945ea90 to your computer and use it in GitHub Desktop.
SET NOCOUNT ON
DECLARE @Starts DATETIME
DECLARE @Ends DATETIME
SET @Starts = '2014-06-05 00:00:00'
SET @Ends = '2014-06-05 23:59:00'
select
ROW_NUMBER() OVER (PARTITION BY DayId, ResourceId ORDER BY DayId, ResourceId)
- ROW_NUMBER() OVER (PARTITION BY DayId, ResourceId, DATEPART(Hour, ActualStart) ORDER BY DayId, ResourceId, DATEPART(Hour, ActualStart)) AS groupId
,*
from servicetime
where
(Actualstart >= @Starts AND ActualEnd <= @Ends)
AND (Closed = 0 OR DenyBooking = 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment