Question : need help with select statement

Hi all,

I have this table:

CREATE TABLE DBO.PositionRecord_type (
      I_YEAR INT NOT NULL,
      I_MONTH INT NOT NULL,
      I_DAY INT NOT NULL,
      I_HOUR INT NOT NULL,
      I_MINUTE INT NOT NULL,
      I_SECOND INT NOT NULL,
      I_MILLISECOND INT NOT NULL,
      I_RADIO_ID INT NOT NULL,
.... several more columns

Units with different I_RADIO_ID's log one record a second to this table.

I need SQL statement to verify that a particular I_RADIO_ID has all the records written to table - in other words, there are no gaps in records coming from this I_RADIO_ID.

Any help is appreciated

Answer : need help with select statement

See if this works in both the way you want (use a sub query to get previous second matching current record) and make that into a view or derived table and then query that for differences in timestamp greater than 1.

(see code snippet)

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
select *
from (
select *
     , (
        select top 1 I_SECOND 
        from @PositionRecord_type t2
        where t2.I_RADIO_ID = t1.I_RADIO_ID
        and t2.I_YEAR = t1.I_YEAR
        and t2.I_MONTH = t1.I_MONTH
        and t2.I_DAY = t1.I_DAY
        and t2.I_HOUR = t1.I_HOUR
        and t2.I_MINUTE = t1.I_MINUTE
        and t2.I_SECOND < t1.I_SECOND
        order by t2.I_SECOND desc
     ) as I_PRE_SECOND
from @PositionRecord_type t1
) derived
where I_SECOND - I_PRE_SECOND <> 1
;
Random Solutions  
 
programming4us programming4us