• OK, read the Forum Etiquette and hope this is correct.

    DECLARE @T TABLE

    (open_front INT

    ,open_rear INT

    ,wrap_count INT

    ,t_stamp DATETIME);

    INSERT INTO @T VALUES (0,0,0,'2013-01-01 01:00');

    INSERT INTO @T VALUES (1,10,1000,'2013-01-01 02:00');

    INSERT INTO @T VALUES (1,20,2000,'2013-01-01 03:00');

    INSERT INTO @T VALUES (2,100,30000,'2013-01-01 23:59');

    INSERT INTO @T VALUES (2,100,31000,'2013-01-02 01:00');

    INSERT INTO @T VALUES (4,100,150,'2013-01-02 01:30');

    INSERT INTO @T VALUES (500,100,4000,'2013-01-02 03:00');

    INSERT INTO @T VALUES (4000,100,31000,'2013-01-02 05:00');

    INSERT INTO @T VALUES (7000,100,8,'2013-01-02 08:00');

    INSERT INTO @T VALUES (30000,100,4000,'2013-01-02 10:00');

    INSERT INTO @T VALUES (8,100,6000,'2013-01-02 21:00');

    DECLARE @StartDate DATETIME

    SET @StartDate = '2013-01-01 00:00'

    DECLARE @EndDate DATETIME

    SET @EndDate= '2013-01-02 23:59';

    The results I would want to see back from the above @StartDate and @EndDate would be:

    Open Front..........Open Rear........Wrap_Count........Date

    2.......................100.................30000................1/1/2013

    32006.................0....................39000................2/1/2013

    (Rembering that the rollover is to be set at 32000 so any decrease in count indicates that 32000 was reached in the PLC)

    Hope this is OK.

    Thanks