I tried to find a way to list rows, that are breaking continuous groups of records. I say groups, because we could use GROUP BY to list values of groups (but that is not applied, we need particular rows).
Sample data:
CREATE TABLE Test (ID INT, NNO INT, DIDX INT, SIDX INT);
-- Valid sample rows
INSERT INTO Test (ID, NNO, DIDX, SIDX) VALUES
( 1, 107 , 7898, 0 ),
( 2, 102 , 7883, 0 ),
( 3, 53 , 7877, 0 ),
( 4, 62 , 7877, 42 ),
( 5, 101 , 7870, 81 ),
( 6, 103 , 7918, 42 ),
( 7, 110 , 7920, 42 ),
( 8, 100 , 7919, 0 ),
( 9, 24 , 7921, 0 ),
(10, 85 , 7904, 0 ),
(11, 85 , 7905, 0 ),
(12, 85 , 7906, 0 ),
(13, 85 , 7907, 0 ),
(14, 85 , 7908, 0 ),
(15, 85 , 7911, 0 ),
(16, 112 , 7876, 0 ),
(17, 5 , 7891, 42 ),
(18, 80 , 7912, 42 ),
(19, 66 , 7912, 91 ),
(20, 22 , 7912, 81 ),
(21, 60 , 7911, 42 ),
(22, 60 , 7912, 0 ),
(23, 78 , 7891, 81 );
-- Disecting row
INSERT INTO Test (ID, NNO, DIDX, SIDX) VALUES
(24, 666 , 7906, 120);
EDIT: I probaly mislead some answers a bit by providing an example too much simplified. It then appeared that perhaps the groups could be only broken by a single row. So please add another row into the example data set:
-- Disecting row -2-
INSERT INTO Test (ID, NNO, DIDX, SIDX) VALUES
(25, 444 , 7906, 160);
Now if ordered the rows in this particular order:
SELECT ID, NNO, DIDX, SIDX
FROM Test
ORDER BY DIDX, SIDX;
...the last inserted row will break (disect) group of records, which have NNO=85:
ID NNO DIDX SIDX
----------- ----------- ----------- -----------
...
10 85 7904 0
11 85 7905 0
12 85 7906 0
24 666 7906 120 <<<<<<<<<<<<<<<<<<<
25 444 7906 160 <<<<<<<<<<<< after EDIT <<<<<<<
13 85 7907 0
14 85 7908 0
15 85 7911 0
...
The result should say 85, which is the broken group, or NULL if we would use healthy data without row ID=24.
Another way to look at the problem is, that for each group (even if it contains 1 row), there may not be records of another group which start or end lies between start and end of the queried group. In the provided example, queried group (85) starts with DIDX=7904 and SIDX=0 and ends with DIDX=7911 and SIDX=0 and nothing can fall into the range - which is the case of record ID=24.
I so far tried some approaches like using ROW_NUMBER() OVER (ORDER BY ...), using WITH with MIN and MAX to go through each group and check, if there are rows that fall within (failed so far to construct it) and GROUP BY with MIN and MAX with aim to cross check it with table rows. No attempt is really worth publishing, so far.
Could anyone advice, how I could check continuity of such defined groups?