• Assuming I've understood what you want, then something like this: -

    SELECT StaffId,

    MIN(EntryDate) AS firstDateEntrySequence, MAX(EntryDate) AS lastDateEntrySequence,

    DATEDIFF(dd,MIN(EntryDate),MAX(EntryDate))+1 AS NumberOfDaysInSequence

    FROM (SELECT StaffId, EntryDate,

    DATEADD(dd, - ROW_NUMBER() OVER (PARTITION BY StaffId ORDER BY EntryDate), EntryDate)

    FROM #yourSampleData

    GROUP BY StaffId, EntryDate) a(StaffId, EntryDate, EntryGroup)

    GROUP BY StaffId, EntryGroup;

    That's based on the following sample data, since you chose not to supply any: -

    IF object_id('tempdb..#yourSampleData') IS NOT NULL

    BEGIN

    DROP TABLE #yourSampleData;

    END;

    SELECT StaffId, EntryDate

    INTO #yourSampleData

    FROM (VALUES(1, '2012-12-12'),(1, '2012-12-13'),(1, '2012-12-15'),

    (2, '2012-12-12'),(2, '2012-12-14'),(2, '2012-12-16')

    )a(StaffId, EntryDate);

    SELECT StaffId, EntryDate

    INTO #yourSampleData

    FROM (SELECT 1, '2012-12-12'

    UNION ALL SELECT 1, '2012-12-13'

    UNION ALL SELECT 1, '2012-12-15'

    UNION ALL SELECT 2, '2012-12-12'

    UNION ALL SELECT 2, '2012-12-14'

    UNION ALL SELECT 2, '2012-12-16'

    )a(StaffId, EntryDate);


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/