Reputation: 1357
Question:
How can I detect which rows have lastModifiedDate < boundary at 30s/minute < approvedDate in T-SQL?
Background:
We have a regular process (Autonomy's ODBCConnector product) which scans a view in our database, and picks up news articles which have changed since it last ran, based on the lastModifiedDate field. This happens every thirty seconds, on the minute and at 30s after the minute.
There was a bug in this process, in that one of the operations was to approve these articles, and that did not cause the lastModifiedDate to change, but changed the approvedDate instead.
So, any article which was modified, picked up, and then approved, will not show up.
This will always be true for articles where approvedDate >= DATEADD(second, 30, lastModifiedDate)
- but that does not pick up all of the articles which still need to be picked up. An article could have a lastModifiedDate of 28/11/2011 15:48:13
and an approvedDate of 28/11/2011 15:48:31
and not be picked up by the process.
NB the approvedDate is not necessarily more recent than the lastModifiedDate
Upvotes: 0
Views: 200
Reputation: 86706
Do you mean you want all records where the approvedDate is in the next 30s block of time relative to the 30s block of time that the lastModifiedDate is in?
LastModifiedDate | ApprovedDate | Include In Results?
00:00:00 | 00:00:00 | No
00:00:00 | 00:00:29 | No
00:00:00 | 00:00:30 | Yes
00:00:00 | 00:00:31 | Yes
00:00:00 | 00:01:01 | No?
00:00:29 | 00:00:29 | No
00:00:29 | 00:00:30 | Yes
00:00:29 | 00:00:31 | Yes
00:00:29 | 00:01:01 | No?
If so, try this?
WHERE
DATEDIFF(second, 0, ApprovedDate ) / 30
=
DATEDIFF(second, 0, LastModifiedDate) / 30 + 1
In No?
should be Yes
in the original table I gave, try this?
WHERE
DATEDIFF(second, 0, ApprovedDate ) / 30
>
DATEDIFF(second, 0, LastModifiedDate) / 30
Or, perhaps...
WHERE
ApprovedDate
>=
DATEADD(second, 30 - DATEDIFF(second, 0, LastModifiedDate) % 30, lastModifiedDate)
Upvotes: 1