The best way to handle this would be to use a timestamp filter in your query, for example:
select * from DOCUMENT
where PENDTX = 1
and DB_CREATE_DATE >= {lastTimeStamp}
and DB_CREATE_DATE < {currentTimeStamp}
Each time you execute the query, you would:
-
Pull the lastTimeStamp from channel cache
-
Calculate your currentTimeStamp
-
Execute the query
-
Update the lastTimeStamp channel cache variable with the currentTimeStamp value
It is important that you do it in this order to ensure that you don't miss any records and you don't overlap or pull any records multiple times. This method assumes that the timestamp value (e.g. DB_CREATE_DATE) is static and does not change.